ソースを参照

daemon/graphdriver/windows: cleanup errors

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 年 前
コミット
3b569cc686
1 ファイル変更9 行追加9 行削除
  1. 9 9
      daemon/graphdriver/windows/windows.go

+ 9 - 9
daemon/graphdriver/windows/windows.go

@@ -110,7 +110,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph
 	// Setting file-mode is a no-op on Windows, so passing "0" to make it more
 	// Setting file-mode is a no-op on Windows, so passing "0" to make it more
 	// transparent that the filemode passed has no effect.
 	// transparent that the filemode passed has no effect.
 	if err = system.MkdirAll(home, 0); err != nil {
 	if err = system.MkdirAll(home, 0); err != nil {
-		return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err)
+		return nil, errors.Wrapf(err, "windowsfilter failed to create '%s'", home)
 	}
 	}
 
 
 	storageOpt := map[string]string{
 	storageOpt := map[string]string{
@@ -124,7 +124,7 @@ func InitFilter(home string, options []string, _ idtools.IdentityMapping) (graph
 
 
 	opts, err := parseStorageOpt(storageOpt)
 	opts, err := parseStorageOpt(storageOpt)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("windowsfilter failed to parse default storage options - %s", err)
+		return nil, errors.Wrap(err, "windowsfilter failed to parse default storage options")
 	}
 	}
 
 
 	d := &Driver{
 	d := &Driver{
@@ -225,7 +225,7 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt
 
 
 		storageOpts, err := parseStorageOpt(storageOpt)
 		storageOpts, err := parseStorageOpt(storageOpt)
 		if err != nil {
 		if err != nil {
-			return fmt.Errorf("Failed to parse storage options - %s", err)
+			return errors.Wrap(err, "failed to parse storage options")
 		}
 		}
 
 
 		sandboxSize := d.defaultStorageOpts.size
 		sandboxSize := d.defaultStorageOpts.size
@@ -244,7 +244,7 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt
 		if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil {
 		if err2 := hcsshim.DestroyLayer(d.info, id); err2 != nil {
 			logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2)
 			logrus.Warnf("Failed to DestroyLayer %s: %s", id, err2)
 		}
 		}
-		return fmt.Errorf("Cannot create layer with missing parent %s: %s", parent, err)
+		return errors.Wrapf(err, "cannot create layer with missing parent %s", parent)
 	}
 	}
 
 
 	if err := d.setLayerChain(id, layerChain); err != nil {
 	if err := d.setLayerChain(id, layerChain); err != nil {
@@ -855,13 +855,13 @@ func (d *Driver) getLayerChain(id string) ([]string, error) {
 	if os.IsNotExist(err) {
 	if os.IsNotExist(err) {
 		return nil, nil
 		return nil, nil
 	} else if err != nil {
 	} else if err != nil {
-		return nil, fmt.Errorf("Unable to read layerchain file - %s", err)
+		return nil, errors.Wrapf(err, "read layerchain file")
 	}
 	}
 
 
 	var layerChain []string
 	var layerChain []string
 	err = json.Unmarshal(content, &layerChain)
 	err = json.Unmarshal(content, &layerChain)
 	if err != nil {
 	if err != nil {
-		return nil, fmt.Errorf("Failed to unmarshall layerchain json - %s", err)
+		return nil, errors.Wrapf(err, "failed to unmarshal layerchain JSON")
 	}
 	}
 
 
 	return layerChain, nil
 	return layerChain, nil
@@ -871,13 +871,13 @@ func (d *Driver) getLayerChain(id string) ([]string, error) {
 func (d *Driver) setLayerChain(id string, chain []string) error {
 func (d *Driver) setLayerChain(id string, chain []string) error {
 	content, err := json.Marshal(&chain)
 	content, err := json.Marshal(&chain)
 	if err != nil {
 	if err != nil {
-		return fmt.Errorf("Failed to marshall layerchain json - %s", err)
+		return errors.Wrap(err, "failed to marshal layerchain JSON")
 	}
 	}
 
 
 	jPath := filepath.Join(d.dir(id), "layerchain.json")
 	jPath := filepath.Join(d.dir(id), "layerchain.json")
-	err = os.WriteFile(jPath, content, 0600)
+	err = os.WriteFile(jPath, content, 0o600)
 	if err != nil {
 	if err != nil {
-		return fmt.Errorf("Unable to write layerchain file - %s", err)
+		return errors.Wrap(err, "write layerchain file")
 	}
 	}
 
 
 	return nil
 	return nil