Browse code

Replace fmt.Errorf() with errors.Errorf() in the cli

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/03/10 03:23:45
Showing 99 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"strings"
6 6
 
7 7
 	"github.com/docker/docker/pkg/term"
8
+	"github.com/pkg/errors"
8 9
 	"github.com/spf13/cobra"
9 10
 )
10 11
 
... ...
@@ -51,7 +52,7 @@ var helpCommand = &cobra.Command{
51 51
 	RunE: func(c *cobra.Command, args []string) error {
52 52
 		cmd, args, e := c.Root().Find(args)
53 53
 		if cmd == nil || e != nil || len(args) > 0 {
54
-			return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
54
+			return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
55 55
 		}
56 56
 
57 57
 		helpFunc := cmd.HelpFunc()
... ...
@@ -2,8 +2,9 @@ package bundlefile
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"fmt"
6 5
 	"io"
6
+
7
+	"github.com/pkg/errors"
7 8
 )
8 9
 
9 10
 // Bundlefile stores the contents of a bundlefile
... ...
@@ -39,12 +40,12 @@ func LoadFile(reader io.Reader) (*Bundlefile, error) {
39 39
 	if err := decoder.Decode(bundlefile); err != nil {
40 40
 		switch jsonErr := err.(type) {
41 41
 		case *json.SyntaxError:
42
-			return nil, fmt.Errorf(
42
+			return nil, errors.Errorf(
43 43
 				"JSON syntax error at byte %v: %s",
44 44
 				jsonErr.Offset,
45 45
 				jsonErr.Error())
46 46
 		case *json.UnmarshalTypeError:
47
-			return nil, fmt.Errorf(
47
+			return nil, errors.Errorf(
48 48
 				"Unexpected type at byte %v. Expected %s but received %s.",
49 49
 				jsonErr.Offset,
50 50
 				jsonErr.Type,
... ...
@@ -1,8 +1,8 @@
1 1
 package command
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"io"
7 7
 	"net/http"
8 8
 	"os"
... ...
@@ -1,7 +1,7 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
4
+	"github.com/pkg/errors"
5 5
 	"io"
6 6
 	"net/http/httputil"
7 7
 
... ...
@@ -1,8 +1,6 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5
-	"fmt"
6 4
 	"io"
7 5
 	"os"
8 6
 	"path/filepath"
... ...
@@ -13,6 +11,7 @@ import (
13 13
 	"github.com/docker/docker/cli/command"
14 14
 	"github.com/docker/docker/pkg/archive"
15 15
 	"github.com/docker/docker/pkg/system"
16
+	"github.com/pkg/errors"
16 17
 	"github.com/spf13/cobra"
17 18
 	"golang.org/x/net/context"
18 19
 )
... ...
@@ -227,7 +226,7 @@ func copyToContainer(ctx context.Context, dockerCli *command.DockerCli, srcPath,
227 227
 		content = os.Stdin
228 228
 		resolvedDstPath = dstInfo.Path
229 229
 		if !dstInfo.IsDir {
230
-			return fmt.Errorf("destination \"%s:%s\" must be a directory", dstContainer, dstPath)
230
+			return errors.Errorf("destination \"%s:%s\" must be a directory", dstContainer, dstPath)
231 231
 		}
232 232
 	} else {
233 233
 		// Prepare source copy info.
... ...
@@ -14,6 +14,7 @@ import (
14 14
 	apiclient "github.com/docker/docker/client"
15 15
 	"github.com/docker/docker/pkg/jsonmessage"
16 16
 	"github.com/docker/docker/registry"
17
+	"github.com/pkg/errors"
17 18
 	"github.com/spf13/cobra"
18 19
 	"github.com/spf13/pflag"
19 20
 	"golang.org/x/net/context"
... ...
@@ -118,7 +119,7 @@ func (cid *cidFile) Close() error {
118 118
 		return nil
119 119
 	}
120 120
 	if err := os.Remove(cid.path); err != nil {
121
-		return fmt.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
121
+		return errors.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
122 122
 	}
123 123
 
124 124
 	return nil
... ...
@@ -126,7 +127,7 @@ func (cid *cidFile) Close() error {
126 126
 
127 127
 func (cid *cidFile) Write(id string) error {
128 128
 	if _, err := cid.file.Write([]byte(id)); err != nil {
129
-		return fmt.Errorf("Failed to write the container ID to the file: %s", err)
129
+		return errors.Errorf("Failed to write the container ID to the file: %s", err)
130 130
 	}
131 131
 	cid.written = true
132 132
 	return nil
... ...
@@ -134,12 +135,12 @@ func (cid *cidFile) Write(id string) error {
134 134
 
135 135
 func newCIDFile(path string) (*cidFile, error) {
136 136
 	if _, err := os.Stat(path); err == nil {
137
-		return nil, fmt.Errorf("Container ID file found, make sure the other container isn't running or delete %s", path)
137
+		return nil, errors.Errorf("Container ID file found, make sure the other container isn't running or delete %s", path)
138 138
 	}
139 139
 
140 140
 	f, err := os.Create(path)
141 141
 	if err != nil {
142
-		return nil, fmt.Errorf("Failed to create the container ID file: %s", err)
142
+		return nil, errors.Errorf("Failed to create the container ID file: %s", err)
143 143
 	}
144 144
 
145 145
 	return &cidFile{path: path, file: f}, nil
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
... ...
@@ -1,7 +1,7 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
4
+	"github.com/pkg/errors"
5 5
 	"io"
6 6
 
7 7
 	"github.com/docker/docker/cli"
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/cli"
... ...
@@ -18,6 +18,7 @@ import (
18 18
 	"github.com/docker/docker/pkg/signal"
19 19
 	runconfigopts "github.com/docker/docker/runconfig/opts"
20 20
 	"github.com/docker/go-connections/nat"
21
+	"github.com/pkg/errors"
21 22
 	"github.com/spf13/pflag"
22 23
 )
23 24
 
... ...
@@ -304,7 +305,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
304 304
 	// Validate the input mac address
305 305
 	if copts.macAddress != "" {
306 306
 		if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil {
307
-			return nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress)
307
+			return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress)
308 308
 		}
309 309
 	}
310 310
 	if copts.stdin {
... ...
@@ -320,7 +321,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
320 320
 
321 321
 	swappiness := copts.swappiness
322 322
 	if swappiness != -1 && (swappiness < 0 || swappiness > 100) {
323
-		return nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
323
+		return nil, errors.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness)
324 324
 	}
325 325
 
326 326
 	var binds []string
... ...
@@ -371,7 +372,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
371 371
 	// Merge in exposed ports to the map of published ports
372 372
 	for _, e := range copts.expose.GetAll() {
373 373
 		if strings.Contains(e, ":") {
374
-			return nil, fmt.Errorf("invalid port format for --expose: %s", e)
374
+			return nil, errors.Errorf("invalid port format for --expose: %s", e)
375 375
 		}
376 376
 		//support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>]
377 377
 		proto, port := nat.SplitProtoPort(e)
... ...
@@ -379,7 +380,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
379 379
 		//if expose a port, the start and end port are the same
380 380
 		start, end, err := nat.ParsePortRange(port)
381 381
 		if err != nil {
382
-			return nil, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err)
382
+			return nil, errors.Errorf("invalid range format for --expose: %s, error: %s", e, err)
383 383
 		}
384 384
 		for i := start; i <= end; i++ {
385 385
 			p, err := nat.NewPort(proto, strconv.FormatUint(i, 10))
... ...
@@ -416,22 +417,22 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
416 416
 
417 417
 	ipcMode := container.IpcMode(copts.ipcMode)
418 418
 	if !ipcMode.Valid() {
419
-		return nil, fmt.Errorf("--ipc: invalid IPC mode")
419
+		return nil, errors.Errorf("--ipc: invalid IPC mode")
420 420
 	}
421 421
 
422 422
 	pidMode := container.PidMode(copts.pidMode)
423 423
 	if !pidMode.Valid() {
424
-		return nil, fmt.Errorf("--pid: invalid PID mode")
424
+		return nil, errors.Errorf("--pid: invalid PID mode")
425 425
 	}
426 426
 
427 427
 	utsMode := container.UTSMode(copts.utsMode)
428 428
 	if !utsMode.Valid() {
429
-		return nil, fmt.Errorf("--uts: invalid UTS mode")
429
+		return nil, errors.Errorf("--uts: invalid UTS mode")
430 430
 	}
431 431
 
432 432
 	usernsMode := container.UsernsMode(copts.usernsMode)
433 433
 	if !usernsMode.Valid() {
434
-		return nil, fmt.Errorf("--userns: invalid USER mode")
434
+		return nil, errors.Errorf("--userns: invalid USER mode")
435 435
 	}
436 436
 
437 437
 	restartPolicy, err := runconfigopts.ParseRestartPolicy(copts.restartPolicy)
... ...
@@ -462,7 +463,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
462 462
 		copts.healthRetries != 0
463 463
 	if copts.noHealthcheck {
464 464
 		if haveHealthSettings {
465
-			return nil, fmt.Errorf("--no-healthcheck conflicts with --health-* options")
465
+			return nil, errors.Errorf("--no-healthcheck conflicts with --health-* options")
466 466
 		}
467 467
 		test := strslice.StrSlice{"NONE"}
468 468
 		healthConfig = &container.HealthConfig{Test: test}
... ...
@@ -473,13 +474,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
473 473
 			probe = strslice.StrSlice(args)
474 474
 		}
475 475
 		if copts.healthInterval < 0 {
476
-			return nil, fmt.Errorf("--health-interval cannot be negative")
476
+			return nil, errors.Errorf("--health-interval cannot be negative")
477 477
 		}
478 478
 		if copts.healthTimeout < 0 {
479
-			return nil, fmt.Errorf("--health-timeout cannot be negative")
479
+			return nil, errors.Errorf("--health-timeout cannot be negative")
480 480
 		}
481 481
 		if copts.healthRetries < 0 {
482
-			return nil, fmt.Errorf("--health-retries cannot be negative")
482
+			return nil, errors.Errorf("--health-retries cannot be negative")
483 483
 		}
484 484
 
485 485
 		healthConfig = &container.HealthConfig{
... ...
@@ -594,7 +595,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
594 594
 	}
595 595
 
596 596
 	if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() {
597
-		return nil, fmt.Errorf("Conflicting options: --restart and --rm")
597
+		return nil, errors.Errorf("Conflicting options: --restart and --rm")
598 598
 	}
599 599
 
600 600
 	// only set this value if the user provided the flag, else it should default to nil
... ...
@@ -656,7 +657,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
656 656
 func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
657 657
 	loggingOptsMap := runconfigopts.ConvertKVStringsToMap(loggingOpts)
658 658
 	if loggingDriver == "none" && len(loggingOpts) > 0 {
659
-		return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver)
659
+		return map[string]string{}, errors.Errorf("invalid logging opts for driver %s", loggingDriver)
660 660
 	}
661 661
 	return loggingOptsMap, nil
662 662
 }
... ...
@@ -669,17 +670,17 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) {
669 669
 			if strings.Contains(opt, ":") {
670 670
 				con = strings.SplitN(opt, ":", 2)
671 671
 			} else {
672
-				return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt)
672
+				return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt)
673 673
 			}
674 674
 		}
675 675
 		if con[0] == "seccomp" && con[1] != "unconfined" {
676 676
 			f, err := ioutil.ReadFile(con[1])
677 677
 			if err != nil {
678
-				return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
678
+				return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
679 679
 			}
680 680
 			b := bytes.NewBuffer(nil)
681 681
 			if err := json.Compact(b, f); err != nil {
682
-				return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
682
+				return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
683 683
 			}
684 684
 			securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes())
685 685
 		}
... ...
@@ -696,7 +697,7 @@ func parseStorageOpts(storageOpts []string) (map[string]string, error) {
696 696
 			opt := strings.SplitN(option, "=", 2)
697 697
 			m[opt[0]] = opt[1]
698 698
 		} else {
699
-			return nil, fmt.Errorf("invalid storage option")
699
+			return nil, errors.Errorf("invalid storage option")
700 700
 		}
701 701
 	}
702 702
 	return m, nil
... ...
@@ -722,7 +723,7 @@ func parseDevice(device string) (container.DeviceMapping, error) {
722 722
 	case 1:
723 723
 		src = arr[0]
724 724
 	default:
725
-		return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
725
+		return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device)
726 726
 	}
727 727
 
728 728
 	if dst == "" {
... ...
@@ -745,7 +746,7 @@ func validateDeviceCgroupRule(val string) (string, error) {
745 745
 		return val, nil
746 746
 	}
747 747
 
748
-	return val, fmt.Errorf("invalid device cgroup format '%s'", val)
748
+	return val, errors.Errorf("invalid device cgroup format '%s'", val)
749 749
 }
750 750
 
751 751
 // validDeviceMode checks if the mode for device is valid or not.
... ...
@@ -781,12 +782,12 @@ func validatePath(val string, validator func(string) bool) (string, error) {
781 781
 	var mode string
782 782
 
783 783
 	if strings.Count(val, ":") > 2 {
784
-		return val, fmt.Errorf("bad format for path: %s", val)
784
+		return val, errors.Errorf("bad format for path: %s", val)
785 785
 	}
786 786
 
787 787
 	split := strings.SplitN(val, ":", 3)
788 788
 	if split[0] == "" {
789
-		return val, fmt.Errorf("bad format for path: %s", val)
789
+		return val, errors.Errorf("bad format for path: %s", val)
790 790
 	}
791 791
 	switch len(split) {
792 792
 	case 1:
... ...
@@ -805,13 +806,13 @@ func validatePath(val string, validator func(string) bool) (string, error) {
805 805
 		containerPath = split[1]
806 806
 		mode = split[2]
807 807
 		if isValid := validator(split[2]); !isValid {
808
-			return val, fmt.Errorf("bad mode specified: %s", mode)
808
+			return val, errors.Errorf("bad mode specified: %s", mode)
809 809
 		}
810 810
 		val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode)
811 811
 	}
812 812
 
813 813
 	if !path.IsAbs(containerPath) {
814
-		return val, fmt.Errorf("%s is not an absolute path", containerPath)
814
+		return val, errors.Errorf("%s is not an absolute path", containerPath)
815 815
 	}
816 816
 	return val, nil
817 817
 }
... ...
@@ -885,5 +886,5 @@ func validateAttach(val string) (string, error) {
885 885
 			return s, nil
886 886
 		}
887 887
 	}
888
-	return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR")
888
+	return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
889 889
 }
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	"github.com/docker/docker/pkg/testutil/assert"
17 17
 	"github.com/docker/docker/runconfig"
18 18
 	"github.com/docker/go-connections/nat"
19
+	"github.com/pkg/errors"
19 20
 	"github.com/spf13/pflag"
20 21
 )
21 22
 
... ...
@@ -224,7 +225,7 @@ func compareRandomizedStrings(a, b, c, d string) error {
224 224
 	if a == d && b == c {
225 225
 		return nil
226 226
 	}
227
-	return fmt.Errorf("strings don't match")
227
+	return errors.Errorf("strings don't match")
228 228
 }
229 229
 
230 230
 // Simple parse with MacAddress validation
... ...
@@ -751,14 +752,14 @@ func callDecodeContainerConfig(volumes []string, binds []string) (*container.Con
751 751
 		w.Config.Volumes[v] = struct{}{}
752 752
 	}
753 753
 	if b, err = json.Marshal(w); err != nil {
754
-		return nil, nil, fmt.Errorf("Error on marshal %s", err.Error())
754
+		return nil, nil, errors.Errorf("Error on marshal %s", err.Error())
755 755
 	}
756 756
 	c, h, _, err = runconfig.DecodeContainerConfig(bytes.NewReader(b))
757 757
 	if err != nil {
758
-		return nil, nil, fmt.Errorf("Error parsing %s: %v", string(b), err)
758
+		return nil, nil, errors.Errorf("Error parsing %s: %v", string(b), err)
759 759
 	}
760 760
 	if c == nil || h == nil {
761
-		return nil, nil, fmt.Errorf("Empty config or hostconfig")
761
+		return nil, nil, errors.Errorf("Empty config or hostconfig")
762 762
 	}
763 763
 
764 764
 	return c, h, err
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/cli"
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
9 9
 	"github.com/docker/go-connections/nat"
10
+	"github.com/pkg/errors"
10 11
 	"github.com/spf13/cobra"
11 12
 	"golang.org/x/net/context"
12 13
 )
... ...
@@ -64,7 +65,7 @@ func runPort(dockerCli *command.DockerCli, opts *portOptions) error {
64 64
 			}
65 65
 			return nil
66 66
 		}
67
-		return fmt.Errorf("Error: No public port '%s' published for %s", natPort, opts.container)
67
+		return errors.Errorf("Error: No public port '%s' published for %s", natPort, opts.container)
68 68
 	}
69 69
 
70 70
 	for from, frontends := range c.NetworkSettings.Ports {
... ...
@@ -1,12 +1,12 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"strings"
7 6
 
8 7
 	"github.com/docker/docker/cli"
9 8
 	"github.com/docker/docker/cli/command"
9
+	"github.com/pkg/errors"
10 10
 	"github.com/spf13/cobra"
11 11
 	"golang.org/x/net/context"
12 12
 )
... ...
@@ -45,7 +45,7 @@ func runRename(dockerCli *command.DockerCli, opts *renameOptions) error {
45 45
 
46 46
 	if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil {
47 47
 		fmt.Fprintln(dockerCli.Err(), err)
48
-		return fmt.Errorf("Error: failed to rename container named %s", oldName)
48
+		return errors.Errorf("Error: failed to rename container named %s", oldName)
49 49
 	}
50 50
 	return nil
51 51
 }
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 	"time"
8 8
 
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/api/types"
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"io"
7 7
 	"net/http/httputil"
8 8
 	"os"
... ...
@@ -1,7 +1,6 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"io"
7 6
 	"net/http/httputil"
... ...
@@ -12,6 +11,7 @@ import (
12 12
 	"github.com/docker/docker/cli/command"
13 13
 	"github.com/docker/docker/pkg/promise"
14 14
 	"github.com/docker/docker/pkg/signal"
15
+	"github.com/pkg/errors"
15 16
 	"github.com/spf13/cobra"
16 17
 	"golang.org/x/net/context"
17 18
 )
... ...
@@ -173,7 +173,7 @@ func startContainersWithoutAttachments(ctx context.Context, dockerCli *command.D
173 173
 	}
174 174
 
175 175
 	if len(failedContainers) > 0 {
176
-		return fmt.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", "))
176
+		return errors.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", "))
177 177
 	}
178 178
 	return nil
179 179
 }
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"io"
7 7
 	"strings"
8 8
 	"sync"
... ...
@@ -2,7 +2,7 @@ package container
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"errors"
5
+	"github.com/pkg/errors"
6 6
 	"io"
7 7
 	"strings"
8 8
 	"sync"
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 	"time"
8 8
 
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/cli"
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	containertypes "github.com/docker/docker/api/types/container"
... ...
@@ -1,8 +1,8 @@
1 1
 package container
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"github.com/docker/docker/cli"
... ...
@@ -2,13 +2,13 @@ package formatter
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io"
7 6
 	"strings"
8 7
 	"text/tabwriter"
9 8
 	"text/template"
10 9
 
11 10
 	"github.com/docker/docker/pkg/templates"
11
+	"github.com/pkg/errors"
12 12
 )
13 13
 
14 14
 // Format keys used to specify certain kinds of output formats
... ...
@@ -64,7 +64,7 @@ func (c *Context) preFormat() {
64 64
 func (c *Context) parseFormat() (*template.Template, error) {
65 65
 	tmpl, err := templates.Parse(c.finalFormat)
66 66
 	if err != nil {
67
-		return tmpl, fmt.Errorf("Template parsing error: %v\n", err)
67
+		return tmpl, errors.Errorf("Template parsing error: %v\n", err)
68 68
 	}
69 69
 	return tmpl, err
70 70
 }
... ...
@@ -85,7 +85,7 @@ func (c *Context) postFormat(tmpl *template.Template, subContext subContext) {
85 85
 
86 86
 func (c *Context) contextFormat(tmpl *template.Template, subContext subContext) error {
87 87
 	if err := tmpl.Execute(c.buffer, subContext); err != nil {
88
-		return fmt.Errorf("Template parsing error: %v\n", err)
88
+		return errors.Errorf("Template parsing error: %v\n", err)
89 89
 	}
90 90
 	if c.Format.IsTable() && c.header != nil {
91 91
 		c.header = subContext.FullHeader()
... ...
@@ -2,9 +2,10 @@ package formatter
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"fmt"
6 5
 	"reflect"
7 6
 	"unicode"
7
+
8
+	"github.com/pkg/errors"
8 9
 )
9 10
 
10 11
 func marshalJSON(x interface{}) ([]byte, error) {
... ...
@@ -19,14 +20,14 @@ func marshalJSON(x interface{}) ([]byte, error) {
19 19
 func marshalMap(x interface{}) (map[string]interface{}, error) {
20 20
 	val := reflect.ValueOf(x)
21 21
 	if val.Kind() != reflect.Ptr {
22
-		return nil, fmt.Errorf("expected a pointer to a struct, got %v", val.Kind())
22
+		return nil, errors.Errorf("expected a pointer to a struct, got %v", val.Kind())
23 23
 	}
24 24
 	if val.IsNil() {
25
-		return nil, fmt.Errorf("expected a pointer to a struct, got nil pointer")
25
+		return nil, errors.Errorf("expected a pointer to a struct, got nil pointer")
26 26
 	}
27 27
 	valElem := val.Elem()
28 28
 	if valElem.Kind() != reflect.Struct {
29
-		return nil, fmt.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind())
29
+		return nil, errors.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind())
30 30
 	}
31 31
 	typ := val.Type()
32 32
 	m := make(map[string]interface{})
... ...
@@ -48,7 +49,7 @@ var unmarshallableNames = map[string]struct{}{"FullHeader": {}}
48 48
 // It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()")
49 49
 func marshalForMethod(typ reflect.Method, val reflect.Value) (string, interface{}, error) {
50 50
 	if val.Kind() != reflect.Func {
51
-		return "", nil, fmt.Errorf("expected func, got %v", val.Kind())
51
+		return "", nil, errors.Errorf("expected func, got %v", val.Kind())
52 52
 	}
53 53
 	name, numIn, numOut := typ.Name, val.Type().NumIn(), val.Type().NumOut()
54 54
 	_, blackListed := unmarshallableNames[name]
... ...
@@ -1,7 +1,6 @@
1 1
 package formatter
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 	"time"
7 6
 
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"github.com/docker/docker/cli/command/inspect"
12 12
 	"github.com/docker/docker/pkg/stringid"
13 13
 	units "github.com/docker/go-units"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 const serviceInspectPrettyTemplate Format = `
... ...
@@ -147,7 +147,7 @@ func ServiceInspectWrite(ctx Context, refs []string, getRef inspect.GetRefFunc)
147 147
 			}
148 148
 			service, ok := serviceI.(swarm.Service)
149 149
 			if !ok {
150
-				return fmt.Errorf("got wrong object to inspect")
150
+				return errors.Errorf("got wrong object to inspect")
151 151
 			}
152 152
 			if err := format(&serviceInspectContext{Service: service}); err != nil {
153 153
 				return err
... ...
@@ -1,12 +1,11 @@
1 1
 package idresolver
2 2
 
3 3
 import (
4
-	"fmt"
5
-
6 4
 	"golang.org/x/net/context"
7 5
 
8 6
 	"github.com/docker/docker/api/types/swarm"
9 7
 	"github.com/docker/docker/client"
8
+	"github.com/pkg/errors"
10 9
 )
11 10
 
12 11
 // IDResolver provides ID to Name resolution.
... ...
@@ -46,7 +45,7 @@ func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string,
46 46
 		}
47 47
 		return service.Spec.Annotations.Name, nil
48 48
 	default:
49
-		return "", fmt.Errorf("unsupported type")
49
+		return "", errors.Errorf("unsupported type")
50 50
 	}
51 51
 
52 52
 }
... ...
@@ -28,6 +28,7 @@ import (
28 28
 	"github.com/docker/docker/pkg/urlutil"
29 29
 	runconfigopts "github.com/docker/docker/runconfig/opts"
30 30
 	units "github.com/docker/go-units"
31
+	"github.com/pkg/errors"
31 32
 	"github.com/spf13/cobra"
32 33
 	"golang.org/x/net/context"
33 34
 )
... ...
@@ -166,14 +167,14 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
166 166
 	case urlutil.IsURL(specifiedContext):
167 167
 		buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName)
168 168
 	default:
169
-		return fmt.Errorf("unable to prepare context: path %q not found", specifiedContext)
169
+		return errors.Errorf("unable to prepare context: path %q not found", specifiedContext)
170 170
 	}
171 171
 
172 172
 	if err != nil {
173 173
 		if options.quiet && urlutil.IsURL(specifiedContext) {
174 174
 			fmt.Fprintln(dockerCli.Err(), progBuff)
175 175
 		}
176
-		return fmt.Errorf("unable to prepare context: %s", err)
176
+		return errors.Errorf("unable to prepare context: %s", err)
177 177
 	}
178 178
 
179 179
 	if tempDir != "" {
... ...
@@ -185,7 +186,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
185 185
 		// And canonicalize dockerfile name to a platform-independent one
186 186
 		relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile)
187 187
 		if err != nil {
188
-			return fmt.Errorf("cannot canonicalize dockerfile path %s: %v", relDockerfile, err)
188
+			return errors.Errorf("cannot canonicalize dockerfile path %s: %v", relDockerfile, err)
189 189
 		}
190 190
 
191 191
 		f, err := os.Open(filepath.Join(contextDir, ".dockerignore"))
... ...
@@ -203,7 +204,7 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
203 203
 		}
204 204
 
205 205
 		if err := build.ValidateContextDirectory(contextDir, excludes); err != nil {
206
-			return fmt.Errorf("Error checking context: '%s'.", err)
206
+			return errors.Errorf("Error checking context: '%s'.", err)
207 207
 		}
208 208
 
209 209
 		// If .dockerignore mentions .dockerignore or the Dockerfile
... ...
@@ -18,6 +18,7 @@ import (
18 18
 	"github.com/docker/docker/pkg/ioutils"
19 19
 	"github.com/docker/docker/pkg/progress"
20 20
 	"github.com/docker/docker/pkg/streamformatter"
21
+	"github.com/pkg/errors"
21 22
 )
22 23
 
23 24
 const (
... ...
@@ -36,7 +37,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
36 36
 	return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
37 37
 		if err != nil {
38 38
 			if os.IsPermission(err) {
39
-				return fmt.Errorf("can't stat '%s'", filePath)
39
+				return errors.Errorf("can't stat '%s'", filePath)
40 40
 			}
41 41
 			if os.IsNotExist(err) {
42 42
 				return nil
... ...
@@ -65,7 +66,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
65 65
 		if !f.IsDir() {
66 66
 			currentFile, err := os.Open(filePath)
67 67
 			if err != nil && os.IsPermission(err) {
68
-				return fmt.Errorf("no permission to read from '%s'", filePath)
68
+				return errors.Errorf("no permission to read from '%s'", filePath)
69 69
 			}
70 70
 			currentFile.Close()
71 71
 		}
... ...
@@ -81,7 +82,7 @@ func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
81 81
 
82 82
 	magic, err := buf.Peek(archive.HeaderSize)
83 83
 	if err != nil && err != io.EOF {
84
-		return nil, "", fmt.Errorf("failed to peek context header from STDIN: %v", err)
84
+		return nil, "", errors.Errorf("failed to peek context header from STDIN: %v", err)
85 85
 	}
86 86
 
87 87
 	if archive.IsArchive(magic) {
... ...
@@ -91,7 +92,7 @@ func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
91 91
 	// Input should be read as a Dockerfile.
92 92
 	tmpDir, err := ioutil.TempDir("", "docker-build-context-")
93 93
 	if err != nil {
94
-		return nil, "", fmt.Errorf("unable to create temporary context directory: %v", err)
94
+		return nil, "", errors.Errorf("unable to create temporary context directory: %v", err)
95 95
 	}
96 96
 
97 97
 	f, err := os.Create(filepath.Join(tmpDir, DefaultDockerfileName))
... ...
@@ -131,10 +132,10 @@ func GetContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
131 131
 // success.
132 132
 func GetContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDockerfile string, err error) {
133 133
 	if _, err := exec.LookPath("git"); err != nil {
134
-		return "", "", fmt.Errorf("unable to find 'git': %v", err)
134
+		return "", "", errors.Errorf("unable to find 'git': %v", err)
135 135
 	}
136 136
 	if absContextDir, err = gitutils.Clone(gitURL); err != nil {
137
-		return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %v", err)
137
+		return "", "", errors.Errorf("unable to 'git clone' to temporary context directory: %v", err)
138 138
 	}
139 139
 
140 140
 	return getDockerfileRelPath(absContextDir, dockerfileName)
... ...
@@ -147,7 +148,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDock
147 147
 func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
148 148
 	response, err := httputils.Download(remoteURL)
149 149
 	if err != nil {
150
-		return nil, "", fmt.Errorf("unable to download remote context %s: %v", remoteURL, err)
150
+		return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
151 151
 	}
152 152
 	progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(out, true)
153 153
 
... ...
@@ -167,7 +168,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (absContextDir, rel
167 167
 	// current directory and not the context directory.
168 168
 	if dockerfileName != "" {
169 169
 		if dockerfileName, err = filepath.Abs(dockerfileName); err != nil {
170
-			return "", "", fmt.Errorf("unable to get absolute path to Dockerfile: %v", err)
170
+			return "", "", errors.Errorf("unable to get absolute path to Dockerfile: %v", err)
171 171
 		}
172 172
 	}
173 173
 
... ...
@@ -179,7 +180,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (absContextDir, rel
179 179
 // the dockerfile in that context directory, and a non-nil error on success.
180 180
 func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDir, relDockerfile string, err error) {
181 181
 	if absContextDir, err = filepath.Abs(givenContextDir); err != nil {
182
-		return "", "", fmt.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err)
182
+		return "", "", errors.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err)
183 183
 	}
184 184
 
185 185
 	// The context dir might be a symbolic link, so follow it to the actual
... ...
@@ -192,17 +193,17 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
192 192
 	if !isUNC(absContextDir) {
193 193
 		absContextDir, err = filepath.EvalSymlinks(absContextDir)
194 194
 		if err != nil {
195
-			return "", "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err)
195
+			return "", "", errors.Errorf("unable to evaluate symlinks in context path: %v", err)
196 196
 		}
197 197
 	}
198 198
 
199 199
 	stat, err := os.Lstat(absContextDir)
200 200
 	if err != nil {
201
-		return "", "", fmt.Errorf("unable to stat context directory %q: %v", absContextDir, err)
201
+		return "", "", errors.Errorf("unable to stat context directory %q: %v", absContextDir, err)
202 202
 	}
203 203
 
204 204
 	if !stat.IsDir() {
205
-		return "", "", fmt.Errorf("context must be a directory: %s", absContextDir)
205
+		return "", "", errors.Errorf("context must be a directory: %s", absContextDir)
206 206
 	}
207 207
 
208 208
 	absDockerfile := givenDockerfile
... ...
@@ -236,23 +237,23 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
236 236
 	if !isUNC(absDockerfile) {
237 237
 		absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
238 238
 		if err != nil {
239
-			return "", "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
239
+			return "", "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
240 240
 		}
241 241
 	}
242 242
 
243 243
 	if _, err := os.Lstat(absDockerfile); err != nil {
244 244
 		if os.IsNotExist(err) {
245
-			return "", "", fmt.Errorf("Cannot locate Dockerfile: %q", absDockerfile)
245
+			return "", "", errors.Errorf("Cannot locate Dockerfile: %q", absDockerfile)
246 246
 		}
247
-		return "", "", fmt.Errorf("unable to stat Dockerfile: %v", err)
247
+		return "", "", errors.Errorf("unable to stat Dockerfile: %v", err)
248 248
 	}
249 249
 
250 250
 	if relDockerfile, err = filepath.Rel(absContextDir, absDockerfile); err != nil {
251
-		return "", "", fmt.Errorf("unable to get relative Dockerfile path: %v", err)
251
+		return "", "", errors.Errorf("unable to get relative Dockerfile path: %v", err)
252 252
 	}
253 253
 
254 254
 	if strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) {
255
-		return "", "", fmt.Errorf("The Dockerfile (%s) must be within the build context (%s)", givenDockerfile, givenContextDir)
255
+		return "", "", errors.Errorf("The Dockerfile (%s) must be within the build context (%s)", givenDockerfile, givenContextDir)
256 256
 	}
257 257
 
258 258
 	return absContextDir, relDockerfile, nil
... ...
@@ -1,7 +1,6 @@
1 1
 package image
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"io"
6 5
 
7 6
 	"golang.org/x/net/context"
... ...
@@ -10,6 +9,7 @@ import (
10 10
 	"github.com/docker/docker/cli/command"
11 11
 	"github.com/docker/docker/pkg/jsonmessage"
12 12
 	"github.com/docker/docker/pkg/system"
13
+	"github.com/pkg/errors"
13 14
 	"github.com/spf13/cobra"
14 15
 )
15 16
 
... ...
@@ -56,7 +56,7 @@ func runLoad(dockerCli *command.DockerCli, opts loadOptions) error {
56 56
 	// To avoid getting stuck, verify that a tar file is given either in
57 57
 	// the input flag or through stdin and if not display an error message and exit.
58 58
 	if opts.input == "" && dockerCli.In().IsTerminal() {
59
-		return fmt.Errorf("requested load from stdin, but stdin is empty")
59
+		return errors.Errorf("requested load from stdin, but stdin is empty")
60 60
 	}
61 61
 
62 62
 	if !dockerCli.Out().IsTerminal() {
... ...
@@ -1,8 +1,8 @@
1 1
 package image
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 	"strings"
7 7
 
8 8
 	"golang.org/x/net/context"
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/cli"
11 11
 	"github.com/docker/docker/cli/command"
12
+	"github.com/pkg/errors"
12 13
 	"github.com/spf13/cobra"
13 14
 )
14 15
 
... ...
@@ -71,7 +72,7 @@ func runRemove(dockerCli *command.DockerCli, opts removeOptions, images []string
71 71
 	}
72 72
 
73 73
 	if len(errs) > 0 {
74
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
74
+		return errors.Errorf("%s", strings.Join(errs, "\n"))
75 75
 	}
76 76
 	return nil
77 77
 }
... ...
@@ -1,7 +1,7 @@
1 1
 package image
2 2
 
3 3
 import (
4
-	"errors"
4
+	"github.com/pkg/errors"
5 5
 	"io"
6 6
 
7 7
 	"golang.org/x/net/context"
... ...
@@ -3,7 +3,6 @@ package image
3 3
 import (
4 4
 	"encoding/hex"
5 5
 	"encoding/json"
6
-	"errors"
7 6
 	"fmt"
8 7
 	"io"
9 8
 	"path"
... ...
@@ -19,6 +18,7 @@ import (
19 19
 	"github.com/docker/notary/client"
20 20
 	"github.com/docker/notary/tuf/data"
21 21
 	"github.com/opencontainers/go-digest"
22
+	"github.com/pkg/errors"
22 23
 	"golang.org/x/net/context"
23 24
 )
24 25
 
... ...
@@ -92,7 +92,7 @@ func PushTrustedReference(cli *command.DockerCli, repoInfo *registry.RepositoryI
92 92
 	}
93 93
 
94 94
 	if cnt > 1 {
95
-		return fmt.Errorf("internal error: only one call to handleTarget expected")
95
+		return errors.Errorf("internal error: only one call to handleTarget expected")
96 96
 	}
97 97
 
98 98
 	if target == nil {
... ...
@@ -195,7 +195,7 @@ func addTargetToAllSignableRoles(repo *client.NotaryRepository, target *client.T
195 195
 	}
196 196
 
197 197
 	if len(signableRoles) == 0 {
198
-		return fmt.Errorf("no valid signing keys for delegation roles")
198
+		return errors.Errorf("no valid signing keys for delegation roles")
199 199
 	}
200 200
 
201 201
 	return repo.AddTarget(target, signableRoles...)
... ...
@@ -245,7 +245,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
245 245
 			refs = append(refs, t)
246 246
 		}
247 247
 		if len(refs) == 0 {
248
-			return trust.NotaryError(ref.Name(), fmt.Errorf("No trusted tags for %s", ref.Name()))
248
+			return trust.NotaryError(ref.Name(), errors.Errorf("No trusted tags for %s", ref.Name()))
249 249
 		}
250 250
 	} else {
251 251
 		t, err := notaryRepo.GetTargetByName(tagged.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
... ...
@@ -255,7 +255,7 @@ func trustedPull(ctx context.Context, cli *command.DockerCli, repoInfo *registry
255 255
 		// Only get the tag if it's in the top level targets role or the releases delegation role
256 256
 		// ignore it if it's in any other delegation roles
257 257
 		if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
258
-			return trust.NotaryError(ref.Name(), fmt.Errorf("No trust data for %s", tagged.Tag()))
258
+			return trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag()))
259 259
 		}
260 260
 
261 261
 		logrus.Debugf("retrieving target for %s role\n", t.Role)
... ...
@@ -347,7 +347,7 @@ func TrustedReference(ctx context.Context, cli *command.DockerCli, ref reference
347 347
 	// Only list tags in the top level targets role or the releases delegation role - ignore
348 348
 	// all other delegation roles
349 349
 	if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
350
-		return nil, trust.NotaryError(repoInfo.Name.Name(), fmt.Errorf("No trust data for %s", ref.Tag()))
350
+		return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", ref.Tag()))
351 351
 	}
352 352
 	r, err := convertTarget(t.Target)
353 353
 	if err != nil {
... ...
@@ -1,7 +1,7 @@
1 1
 package command
2 2
 
3 3
 import (
4
-	"errors"
4
+	"github.com/pkg/errors"
5 5
 	"io"
6 6
 	"os"
7 7
 	"runtime"
... ...
@@ -3,7 +3,6 @@ package inspect
3 3
 import (
4 4
 	"bytes"
5 5
 	"encoding/json"
6
-	"fmt"
7 6
 	"io"
8 7
 	"strings"
9 8
 	"text/template"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"github.com/Sirupsen/logrus"
12 12
 	"github.com/docker/docker/cli"
13 13
 	"github.com/docker/docker/pkg/templates"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 // Inspector defines an interface to implement to process elements
... ...
@@ -44,7 +44,7 @@ func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, e
44 44
 
45 45
 	tmpl, err := templates.Parse(tmplStr)
46 46
 	if err != nil {
47
-		return nil, fmt.Errorf("Template parsing error: %s", err)
47
+		return nil, errors.Errorf("Template parsing error: %s", err)
48 48
 	}
49 49
 	return NewTemplateInspector(out, tmpl), nil
50 50
 }
... ...
@@ -94,7 +94,7 @@ func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte)
94 94
 	buffer := new(bytes.Buffer)
95 95
 	if err := i.tmpl.Execute(buffer, typedElement); err != nil {
96 96
 		if rawElement == nil {
97
-			return fmt.Errorf("Template parsing error: %v", err)
97
+			return errors.Errorf("Template parsing error: %v", err)
98 98
 		}
99 99
 		return i.tryRawInspectFallback(rawElement)
100 100
 	}
... ...
@@ -112,12 +112,12 @@ func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error {
112 112
 	dec := json.NewDecoder(rdr)
113 113
 
114 114
 	if rawErr := dec.Decode(&raw); rawErr != nil {
115
-		return fmt.Errorf("unable to read inspect data: %v", rawErr)
115
+		return errors.Errorf("unable to read inspect data: %v", rawErr)
116 116
 	}
117 117
 
118 118
 	tmplMissingKey := i.tmpl.Option("missingkey=error")
119 119
 	if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
120
-		return fmt.Errorf("Template parsing error: %v", rawErr)
120
+		return errors.Errorf("Template parsing error: %v", rawErr)
121 121
 	}
122 122
 
123 123
 	i.buffer.Write(buffer.Bytes())
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/cli/command"
14 14
 	"github.com/docker/docker/opts"
15 15
 	runconfigopts "github.com/docker/docker/runconfig/opts"
16
+	"github.com/pkg/errors"
16 17
 	"github.com/spf13/cobra"
17 18
 )
18 19
 
... ...
@@ -110,7 +111,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
110 110
 // structured ipam data.
111 111
 func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]string) ([]network.IPAMConfig, error) {
112 112
 	if len(subnets) < len(ranges) || len(subnets) < len(gateways) {
113
-		return nil, fmt.Errorf("every ip-range or gateway must have a corresponding subnet")
113
+		return nil, errors.Errorf("every ip-range or gateway must have a corresponding subnet")
114 114
 	}
115 115
 	iData := map[string]*network.IPAMConfig{}
116 116
 
... ...
@@ -126,7 +127,7 @@ func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]str
126 126
 				return nil, err
127 127
 			}
128 128
 			if ok1 || ok2 {
129
-				return nil, fmt.Errorf("multiple overlapping subnet configuration is not supported")
129
+				return nil, errors.Errorf("multiple overlapping subnet configuration is not supported")
130 130
 			}
131 131
 		}
132 132
 		iData[s] = &network.IPAMConfig{Subnet: s, AuxAddress: map[string]string{}}
... ...
@@ -144,14 +145,14 @@ func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]str
144 144
 				continue
145 145
 			}
146 146
 			if iData[s].IPRange != "" {
147
-				return nil, fmt.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s)
147
+				return nil, errors.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s)
148 148
 			}
149 149
 			d := iData[s]
150 150
 			d.IPRange = r
151 151
 			match = true
152 152
 		}
153 153
 		if !match {
154
-			return nil, fmt.Errorf("no matching subnet for range %s", r)
154
+			return nil, errors.Errorf("no matching subnet for range %s", r)
155 155
 		}
156 156
 	}
157 157
 
... ...
@@ -167,14 +168,14 @@ func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]str
167 167
 				continue
168 168
 			}
169 169
 			if iData[s].Gateway != "" {
170
-				return nil, fmt.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s)
170
+				return nil, errors.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s)
171 171
 			}
172 172
 			d := iData[s]
173 173
 			d.Gateway = g
174 174
 			match = true
175 175
 		}
176 176
 		if !match {
177
-			return nil, fmt.Errorf("no matching subnet for gateway %s", g)
177
+			return nil, errors.Errorf("no matching subnet for gateway %s", g)
178 178
 		}
179 179
 	}
180 180
 
... ...
@@ -193,7 +194,7 @@ func consolidateIpam(subnets, ranges, gateways []string, auxaddrs map[string]str
193 193
 			match = true
194 194
 		}
195 195
 		if !match {
196
-			return nil, fmt.Errorf("no matching subnet for aux-address %s", aa)
196
+			return nil, errors.Errorf("no matching subnet for aux-address %s", aa)
197 197
 		}
198 198
 	}
199 199
 
... ...
@@ -211,13 +212,13 @@ func subnetMatches(subnet, data string) (bool, error) {
211 211
 
212 212
 	_, s, err := net.ParseCIDR(subnet)
213 213
 	if err != nil {
214
-		return false, fmt.Errorf("Invalid subnet %s : %v", s, err)
214
+		return false, errors.Errorf("Invalid subnet %s : %v", s, err)
215 215
 	}
216 216
 
217 217
 	if strings.Contains(data, "/") {
218 218
 		ip, _, err = net.ParseCIDR(data)
219 219
 		if err != nil {
220
-			return false, fmt.Errorf("Invalid cidr %s : %v", data, err)
220
+			return false, errors.Errorf("Invalid cidr %s : %v", data, err)
221 221
 		}
222 222
 	} else {
223 223
 		ip = net.ParseIP(data)
... ...
@@ -2,12 +2,12 @@ package node
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/api/types/swarm"
10 9
 	"github.com/docker/docker/cli/internal/test"
10
+	"github.com/pkg/errors"
11 11
 	// Import builders to get the builder function as package function
12 12
 	. "github.com/docker/docker/cli/internal/test/builders"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -26,14 +26,14 @@ func TestNodeDemoteErrors(t *testing.T) {
26 26
 		{
27 27
 			args: []string{"nodeID"},
28 28
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
29
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
29
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
30 30
 			},
31 31
 			expectedError: "error inspecting the node",
32 32
 		},
33 33
 		{
34 34
 			args: []string{"nodeID"},
35 35
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
36
-				return fmt.Errorf("error updating the node")
36
+				return errors.Errorf("error updating the node")
37 37
 			},
38 38
 			expectedError: "error updating the node",
39 39
 		},
... ...
@@ -60,7 +60,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
60 60
 			},
61 61
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
62 62
 				if node.Role != swarm.NodeRoleWorker {
63
-					return fmt.Errorf("expected role worker, got %s", node.Role)
63
+					return errors.Errorf("expected role worker, got %s", node.Role)
64 64
 				}
65 65
 				return nil
66 66
 			},
... ...
@@ -78,7 +78,7 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
78 78
 			},
79 79
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
80 80
 				if node.Role != swarm.NodeRoleWorker {
81
-					return fmt.Errorf("expected role worker, got %s", node.Role)
81
+					return errors.Errorf("expected role worker, got %s", node.Role)
82 82
 				}
83 83
 				return nil
84 84
 			},
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/api/types/swarm"
11 11
 	"github.com/docker/docker/cli/internal/test"
12
+	"github.com/pkg/errors"
12 13
 	// Import builders to get the builder function as package function
13 14
 	. "github.com/docker/docker/cli/internal/test/builders"
14 15
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -29,24 +30,24 @@ func TestNodeInspectErrors(t *testing.T) {
29 29
 		{
30 30
 			args: []string{"self"},
31 31
 			infoFunc: func() (types.Info, error) {
32
-				return types.Info{}, fmt.Errorf("error asking for node info")
32
+				return types.Info{}, errors.Errorf("error asking for node info")
33 33
 			},
34 34
 			expectedError: "error asking for node info",
35 35
 		},
36 36
 		{
37 37
 			args: []string{"nodeID"},
38 38
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
39
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
39
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
40 40
 			},
41 41
 			infoFunc: func() (types.Info, error) {
42
-				return types.Info{}, fmt.Errorf("error asking for node info")
42
+				return types.Info{}, errors.Errorf("error asking for node info")
43 43
 			},
44 44
 			expectedError: "error inspecting the node",
45 45
 		},
46 46
 		{
47 47
 			args: []string{"self"},
48 48
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
49
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
49
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
50 50
 			},
51 51
 			infoFunc: func() (types.Info, error) {
52 52
 				return types.Info{}, nil
... ...
@@ -59,7 +60,7 @@ func TestNodeInspectErrors(t *testing.T) {
59 59
 				"pretty": "true",
60 60
 			},
61 61
 			infoFunc: func() (types.Info, error) {
62
-				return types.Info{}, fmt.Errorf("error asking for node info")
62
+				return types.Info{}, errors.Errorf("error asking for node info")
63 63
 			},
64 64
 			expectedError: "error asking for node info",
65 65
 		},
... ...
@@ -2,13 +2,13 @@ package node
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/api/types"
10 9
 	"github.com/docker/docker/api/types/swarm"
11 10
 	"github.com/docker/docker/cli/internal/test"
11
+	"github.com/pkg/errors"
12 12
 	// Import builders to get the builder function as package function
13 13
 	. "github.com/docker/docker/cli/internal/test/builders"
14 14
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -22,7 +22,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
22 22
 	}{
23 23
 		{
24 24
 			nodeListFunc: func() ([]swarm.Node, error) {
25
-				return []swarm.Node{}, fmt.Errorf("error listing nodes")
25
+				return []swarm.Node{}, errors.Errorf("error listing nodes")
26 26
 			},
27 27
 			expectedError: "error listing nodes",
28 28
 		},
... ...
@@ -35,7 +35,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
35 35
 				}, nil
36 36
 			},
37 37
 			infoFunc: func() (types.Info, error) {
38
-				return types.Info{}, fmt.Errorf("error asking for node info")
38
+				return types.Info{}, errors.Errorf("error asking for node info")
39 39
 			},
40 40
 			expectedError: "error asking for node info",
41 41
 		},
... ...
@@ -2,12 +2,12 @@ package node
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/api/types/swarm"
10 9
 	"github.com/docker/docker/cli/internal/test"
10
+	"github.com/pkg/errors"
11 11
 	// Import builders to get the builder function as package function
12 12
 	. "github.com/docker/docker/cli/internal/test/builders"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -26,14 +26,14 @@ func TestNodePromoteErrors(t *testing.T) {
26 26
 		{
27 27
 			args: []string{"nodeID"},
28 28
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
29
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
29
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
30 30
 			},
31 31
 			expectedError: "error inspecting the node",
32 32
 		},
33 33
 		{
34 34
 			args: []string{"nodeID"},
35 35
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
36
-				return fmt.Errorf("error updating the node")
36
+				return errors.Errorf("error updating the node")
37 37
 			},
38 38
 			expectedError: "error updating the node",
39 39
 		},
... ...
@@ -60,7 +60,7 @@ func TestNodePromoteNoChange(t *testing.T) {
60 60
 			},
61 61
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
62 62
 				if node.Role != swarm.NodeRoleManager {
63
-					return fmt.Errorf("expected role manager, got %s", node.Role)
63
+					return errors.Errorf("expected role manager, got %s", node.Role)
64 64
 				}
65 65
 				return nil
66 66
 			},
... ...
@@ -78,7 +78,7 @@ func TestNodePromoteMultipleNode(t *testing.T) {
78 78
 			},
79 79
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
80 80
 				if node.Role != swarm.NodeRoleManager {
81
-					return fmt.Errorf("expected role manager, got %s", node.Role)
81
+					return errors.Errorf("expected role manager, got %s", node.Role)
82 82
 				}
83 83
 				return nil
84 84
 			},
... ...
@@ -1,7 +1,6 @@
1 1
 package node
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 
7 6
 	"github.com/docker/docker/api/types"
... ...
@@ -12,6 +11,7 @@ import (
12 12
 	"github.com/docker/docker/cli/command/idresolver"
13 13
 	"github.com/docker/docker/cli/command/task"
14 14
 	"github.com/docker/docker/opts"
15
+	"github.com/pkg/errors"
15 16
 	"github.com/spf13/cobra"
16 17
 	"golang.org/x/net/context"
17 18
 )
... ...
@@ -100,7 +100,7 @@ func runPs(dockerCli command.Cli, opts psOptions) error {
100 100
 	}
101 101
 
102 102
 	if len(errs) > 0 {
103
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
103
+		return errors.Errorf("%s", strings.Join(errs, "\n"))
104 104
 	}
105 105
 
106 106
 	return nil
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types"
11 11
 	"github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/cli/internal/test"
13
+	"github.com/pkg/errors"
13 14
 	// Import builders to get the builder function as package function
14 15
 	. "github.com/docker/docker/cli/internal/test/builders"
15 16
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -28,21 +29,21 @@ func TestNodePsErrors(t *testing.T) {
28 28
 	}{
29 29
 		{
30 30
 			infoFunc: func() (types.Info, error) {
31
-				return types.Info{}, fmt.Errorf("error asking for node info")
31
+				return types.Info{}, errors.Errorf("error asking for node info")
32 32
 			},
33 33
 			expectedError: "error asking for node info",
34 34
 		},
35 35
 		{
36 36
 			args: []string{"nodeID"},
37 37
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
38
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
38
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
39 39
 			},
40 40
 			expectedError: "error inspecting the node",
41 41
 		},
42 42
 		{
43 43
 			args: []string{"nodeID"},
44 44
 			taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) {
45
-				return []swarm.Task{}, fmt.Errorf("error returning the task list")
45
+				return []swarm.Task{}, errors.Errorf("error returning the task list")
46 46
 			},
47 47
 			expectedError: "error returning the task list",
48 48
 		},
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/cli"
11 11
 	"github.com/docker/docker/cli/command"
12
+	"github.com/pkg/errors"
12 13
 	"github.com/spf13/cobra"
13 14
 )
14 15
 
... ...
@@ -49,7 +50,7 @@ func runRemove(dockerCli command.Cli, args []string, opts removeOptions) error {
49 49
 	}
50 50
 
51 51
 	if len(errs) > 0 {
52
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
52
+		return errors.Errorf("%s", strings.Join(errs, "\n"))
53 53
 	}
54 54
 
55 55
 	return nil
... ...
@@ -2,12 +2,12 @@ package node
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/cli/internal/test"
10 9
 	"github.com/docker/docker/pkg/testutil/assert"
10
+	"github.com/pkg/errors"
11 11
 )
12 12
 
13 13
 func TestNodeRemoveErrors(t *testing.T) {
... ...
@@ -22,7 +22,7 @@ func TestNodeRemoveErrors(t *testing.T) {
22 22
 		{
23 23
 			args: []string{"nodeID"},
24 24
 			nodeRemoveFunc: func() error {
25
-				return fmt.Errorf("error removing the node")
25
+				return errors.Errorf("error removing the node")
26 26
 			},
27 27
 			expectedError: "error removing the node",
28 28
 		},
... ...
@@ -1,7 +1,6 @@
1 1
 package node
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 
7 6
 	"github.com/docker/docker/api/types/swarm"
... ...
@@ -9,6 +8,7 @@ import (
9 9
 	"github.com/docker/docker/cli/command"
10 10
 	"github.com/docker/docker/opts"
11 11
 	runconfigopts "github.com/docker/docker/runconfig/opts"
12
+	"github.com/pkg/errors"
12 13
 	"github.com/spf13/cobra"
13 14
 	"github.com/spf13/pflag"
14 15
 	"golang.org/x/net/context"
... ...
@@ -104,7 +104,7 @@ func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error {
104 104
 			for _, k := range keys {
105 105
 				// if a key doesn't exist, fail the command explicitly
106 106
 				if _, exists := spec.Annotations.Labels[k]; !exists {
107
-					return fmt.Errorf("key %s doesn't exist in node's labels", k)
107
+					return errors.Errorf("key %s doesn't exist in node's labels", k)
108 108
 				}
109 109
 				delete(spec.Annotations.Labels, k)
110 110
 			}
... ...
@@ -2,12 +2,12 @@ package node
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/api/types/swarm"
10 9
 	"github.com/docker/docker/cli/internal/test"
10
+	"github.com/pkg/errors"
11 11
 	// Import builders to get the builder function as package function
12 12
 	. "github.com/docker/docker/cli/internal/test/builders"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -31,14 +31,14 @@ func TestNodeUpdateErrors(t *testing.T) {
31 31
 		{
32 32
 			args: []string{"nodeID"},
33 33
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
34
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
34
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
35 35
 			},
36 36
 			expectedError: "error inspecting the node",
37 37
 		},
38 38
 		{
39 39
 			args: []string{"nodeID"},
40 40
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
41
-				return fmt.Errorf("error updating the node")
41
+				return errors.Errorf("error updating the node")
42 42
 			},
43 43
 			expectedError: "error updating the node",
44 44
 		},
... ...
@@ -88,7 +88,7 @@ func TestNodeUpdate(t *testing.T) {
88 88
 			},
89 89
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
90 90
 				if node.Role != swarm.NodeRoleManager {
91
-					return fmt.Errorf("expected role manager, got %s", node.Role)
91
+					return errors.Errorf("expected role manager, got %s", node.Role)
92 92
 				}
93 93
 				return nil
94 94
 			},
... ...
@@ -103,7 +103,7 @@ func TestNodeUpdate(t *testing.T) {
103 103
 			},
104 104
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
105 105
 				if node.Availability != swarm.NodeAvailabilityDrain {
106
-					return fmt.Errorf("expected drain availability, got %s", node.Availability)
106
+					return errors.Errorf("expected drain availability, got %s", node.Availability)
107 107
 				}
108 108
 				return nil
109 109
 			},
... ...
@@ -118,7 +118,7 @@ func TestNodeUpdate(t *testing.T) {
118 118
 			},
119 119
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
120 120
 				if _, present := node.Annotations.Labels["lbl"]; !present {
121
-					return fmt.Errorf("expected 'lbl' label, got %v", node.Annotations.Labels)
121
+					return errors.Errorf("expected 'lbl' label, got %v", node.Annotations.Labels)
122 122
 				}
123 123
 				return nil
124 124
 			},
... ...
@@ -133,7 +133,7 @@ func TestNodeUpdate(t *testing.T) {
133 133
 			},
134 134
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
135 135
 				if value, present := node.Annotations.Labels["key"]; !present || value != "value" {
136
-					return fmt.Errorf("expected 'key' label to be 'value', got %v", node.Annotations.Labels)
136
+					return errors.Errorf("expected 'key' label to be 'value', got %v", node.Annotations.Labels)
137 137
 				}
138 138
 				return nil
139 139
 			},
... ...
@@ -150,7 +150,7 @@ func TestNodeUpdate(t *testing.T) {
150 150
 			},
151 151
 			nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error {
152 152
 				if len(node.Annotations.Labels) > 0 {
153
-					return fmt.Errorf("expected no labels, got %v", node.Annotations.Labels)
153
+					return errors.Errorf("expected no labels, got %v", node.Annotations.Labels)
154 154
 				}
155 155
 				return nil
156 156
 			},
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/cli"
14 14
 	"github.com/docker/docker/cli/command"
15 15
 	"github.com/docker/docker/pkg/archive"
16
+	"github.com/pkg/errors"
16 17
 	"github.com/spf13/cobra"
17 18
 	"golang.org/x/net/context"
18 19
 )
... ...
@@ -50,7 +51,7 @@ func validateContextDir(contextDir string) (string, error) {
50 50
 	}
51 51
 
52 52
 	if !stat.IsDir() {
53
-		return "", fmt.Errorf("context must be a directory")
53
+		return "", errors.Errorf("context must be a directory")
54 54
 	}
55 55
 
56 56
 	return absContextDir, nil
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"github.com/docker/docker/api/types"
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
9
+	"github.com/pkg/errors"
9 10
 	"github.com/spf13/cobra"
10 11
 	"golang.org/x/net/context"
11 12
 )
... ...
@@ -36,7 +37,7 @@ func newEnableCommand(dockerCli *command.DockerCli) *cobra.Command {
36 36
 func runEnable(dockerCli *command.DockerCli, opts *enableOpts) error {
37 37
 	name := opts.name
38 38
 	if opts.timeout < 0 {
39
-		return fmt.Errorf("negative timeout %d is invalid", opts.timeout)
39
+		return errors.Errorf("negative timeout %d is invalid", opts.timeout)
40 40
 	}
41 41
 
42 42
 	if err := dockerCli.Client().PluginEnable(context.Background(), name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil {
... ...
@@ -1,7 +1,6 @@
1 1
 package plugin
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"strings"
7 6
 
... ...
@@ -12,6 +11,7 @@ import (
12 12
 	"github.com/docker/docker/cli/command/image"
13 13
 	"github.com/docker/docker/pkg/jsonmessage"
14 14
 	"github.com/docker/docker/registry"
15
+	"github.com/pkg/errors"
15 16
 	"github.com/spf13/cobra"
16 17
 	"github.com/spf13/pflag"
17 18
 	"golang.org/x/net/context"
... ...
@@ -92,7 +92,7 @@ func buildPullConfig(ctx context.Context, dockerCli *command.DockerCli, opts plu
92 92
 		ref = reference.TagNameOnly(ref)
93 93
 		nt, ok := ref.(reference.NamedTagged)
94 94
 		if !ok {
95
-			return types.PluginInstallOptions{}, fmt.Errorf("invalid name: %s", ref.String())
95
+			return types.PluginInstallOptions{}, errors.Errorf("invalid name: %s", ref.String())
96 96
 		}
97 97
 
98 98
 		ctx := context.Background()
... ...
@@ -132,7 +132,7 @@ func runInstall(dockerCli *command.DockerCli, opts pluginOptions) error {
132 132
 			return err
133 133
 		}
134 134
 		if _, ok := aref.(reference.Canonical); ok {
135
-			return fmt.Errorf("invalid name: %s", opts.localName)
135
+			return errors.Errorf("invalid name: %s", opts.localName)
136 136
 		}
137 137
 		localName = reference.FamiliarString(reference.TagNameOnly(aref))
138 138
 	}
... ...
@@ -1,8 +1,6 @@
1 1
 package plugin
2 2
 
3 3
 import (
4
-	"fmt"
5
-
6 4
 	"golang.org/x/net/context"
7 5
 
8 6
 	"github.com/docker/distribution/reference"
... ...
@@ -11,6 +9,7 @@ import (
11 11
 	"github.com/docker/docker/cli/command/image"
12 12
 	"github.com/docker/docker/pkg/jsonmessage"
13 13
 	"github.com/docker/docker/registry"
14
+	"github.com/pkg/errors"
14 15
 	"github.com/spf13/cobra"
15 16
 )
16 17
 
... ...
@@ -37,7 +36,7 @@ func runPush(dockerCli *command.DockerCli, name string) error {
37 37
 		return err
38 38
 	}
39 39
 	if _, ok := named.(reference.Canonical); ok {
40
-		return fmt.Errorf("invalid name: %s", name)
40
+		return errors.Errorf("invalid name: %s", name)
41 41
 	}
42 42
 
43 43
 	named = reference.TagNameOnly(named)
... ...
@@ -39,11 +39,11 @@ func runUpgrade(dockerCli *command.DockerCli, opts pluginOptions) error {
39 39
 	ctx := context.Background()
40 40
 	p, _, err := dockerCli.Client().PluginInspectWithRaw(ctx, opts.localName)
41 41
 	if err != nil {
42
-		return fmt.Errorf("error reading plugin data: %v", err)
42
+		return errors.Errorf("error reading plugin data: %v", err)
43 43
 	}
44 44
 
45 45
 	if p.Enabled {
46
-		return fmt.Errorf("the plugin must be disabled before upgrading")
46
+		return errors.Errorf("the plugin must be disabled before upgrading")
47 47
 	}
48 48
 
49 49
 	opts.localName = p.Name
... ...
@@ -17,6 +17,7 @@ import (
17 17
 	registrytypes "github.com/docker/docker/api/types/registry"
18 18
 	"github.com/docker/docker/pkg/term"
19 19
 	"github.com/docker/docker/registry"
20
+	"github.com/pkg/errors"
20 21
 )
21 22
 
22 23
 // ElectAuthServer returns the default registry to use (by asking the daemon)
... ...
@@ -95,7 +96,7 @@ func ConfigureAuth(cli *DockerCli, flUser, flPassword, serverAddress string, isD
95 95
 	// will hit this if you attempt docker login from mintty where stdin
96 96
 	// is a pipe, not a character based console.
97 97
 	if flPassword == "" && !cli.In().IsTerminal() {
98
-		return authconfig, fmt.Errorf("Error: Cannot perform an interactive login from a non TTY device")
98
+		return authconfig, errors.Errorf("Error: Cannot perform an interactive login from a non TTY device")
99 99
 	}
100 100
 
101 101
 	authconfig.Username = strings.TrimSpace(authconfig.Username)
... ...
@@ -113,7 +114,7 @@ func ConfigureAuth(cli *DockerCli, flUser, flPassword, serverAddress string, isD
113 113
 		}
114 114
 	}
115 115
 	if flUser == "" {
116
-		return authconfig, fmt.Errorf("Error: Non-null Username Required")
116
+		return authconfig, errors.Errorf("Error: Non-null Username Required")
117 117
 	}
118 118
 	if flPassword == "" {
119 119
 		oldState, err := term.SaveState(cli.In().FD())
... ...
@@ -128,7 +129,7 @@ func ConfigureAuth(cli *DockerCli, flUser, flPassword, serverAddress string, isD
128 128
 
129 129
 		term.RestoreTerminal(cli.In().FD(), oldState)
130 130
 		if flPassword == "" {
131
-			return authconfig, fmt.Errorf("Error: Password Required")
131
+			return authconfig, errors.Errorf("Error: Password Required")
132 132
 		}
133 133
 	}
134 134
 
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"github.com/docker/docker/cli"
9 9
 	"github.com/docker/docker/cli/command"
10 10
 	"github.com/docker/docker/registry"
11
+	"github.com/pkg/errors"
11 12
 	"github.com/spf13/cobra"
12 13
 )
13 14
 
... ...
@@ -76,7 +77,7 @@ func runLogin(dockerCli *command.DockerCli, opts loginOptions) error {
76 76
 		authConfig.IdentityToken = response.IdentityToken
77 77
 	}
78 78
 	if err := dockerCli.CredentialsStore(serverAddress).Store(authConfig); err != nil {
79
-		return fmt.Errorf("Error saving credentials: %v", err)
79
+		return errors.Errorf("Error saving credentials: %v", err)
80 80
 	}
81 81
 
82 82
 	if response.Status != "" {
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker/opts"
12 12
 	"github.com/docker/docker/pkg/system"
13 13
 	runconfigopts "github.com/docker/docker/runconfig/opts"
14
+	"github.com/pkg/errors"
14 15
 	"github.com/spf13/cobra"
15 16
 	"golang.org/x/net/context"
16 17
 )
... ...
@@ -58,7 +59,7 @@ func runSecretCreate(dockerCli *command.DockerCli, options createOptions) error
58 58
 
59 59
 	secretData, err := ioutil.ReadAll(in)
60 60
 	if err != nil {
61
-		return fmt.Errorf("Error reading content from %q: %v", options.file, err)
61
+		return errors.Errorf("Error reading content from %q: %v", options.file, err)
62 62
 	}
63 63
 
64 64
 	spec := swarm.SecretSpec{
... ...
@@ -6,6 +6,7 @@ import (
6 6
 
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
9
+	"github.com/pkg/errors"
9 10
 	"github.com/spf13/cobra"
10 11
 	"golang.org/x/net/context"
11 12
 )
... ...
@@ -45,7 +46,7 @@ func runSecretRemove(dockerCli *command.DockerCli, opts removeOptions) error {
45 45
 	}
46 46
 
47 47
 	if len(errs) > 0 {
48
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
48
+		return errors.Errorf("%s", strings.Join(errs, "\n"))
49 49
 	}
50 50
 
51 51
 	return nil
... ...
@@ -1,7 +1,6 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 
7 6
 	"golang.org/x/net/context"
... ...
@@ -10,6 +9,7 @@ import (
10 10
 	"github.com/docker/docker/cli/command"
11 11
 	"github.com/docker/docker/cli/command/formatter"
12 12
 	apiclient "github.com/docker/docker/client"
13
+	"github.com/pkg/errors"
13 14
 	"github.com/spf13/cobra"
14 15
 )
15 16
 
... ...
@@ -30,7 +30,7 @@ func newInspectCommand(dockerCli *command.DockerCli) *cobra.Command {
30 30
 			opts.refs = args
31 31
 
32 32
 			if opts.pretty && len(opts.format) > 0 {
33
-				return fmt.Errorf("--format is incompatible with human friendly format")
33
+				return errors.Errorf("--format is incompatible with human friendly format")
34 34
 			}
35 35
 			return runInspect(dockerCli, opts)
36 36
 		},
... ...
@@ -55,7 +55,7 @@ func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
55 55
 		if err == nil || !apiclient.IsErrServiceNotFound(err) {
56 56
 			return service, nil, err
57 57
 		}
58
-		return nil, nil, fmt.Errorf("Error: no such service: %s", ref)
58
+		return nil, nil, errors.Errorf("Error: no such service: %s", ref)
59 59
 	}
60 60
 
61 61
 	f := opts.format
... ...
@@ -69,7 +69,7 @@ func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
69 69
 	// check if the user is trying to apply a template to the pretty format, which
70 70
 	// is not supported
71 71
 	if strings.HasPrefix(f, "pretty") && f != "pretty" {
72
-		return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
72
+		return errors.Errorf("Cannot supply extra formatting options to the pretty template")
73 73
 	}
74 74
 
75 75
 	serviceCtx := formatter.Context{
... ...
@@ -17,6 +17,7 @@ import (
17 17
 	"github.com/docker/docker/client"
18 18
 	"github.com/docker/docker/pkg/stdcopy"
19 19
 	"github.com/docker/docker/pkg/stringid"
20
+	"github.com/pkg/errors"
20 21
 	"github.com/spf13/cobra"
21 22
 )
22 23
 
... ...
@@ -170,7 +171,7 @@ func (lw *logWriter) Write(buf []byte) (int, error) {
170 170
 
171 171
 	parts := bytes.SplitN(buf, []byte(" "), numParts)
172 172
 	if len(parts) != numParts {
173
-		return 0, fmt.Errorf("invalid context in log message: %v", string(buf))
173
+		return 0, errors.Errorf("invalid context in log message: %v", string(buf))
174 174
 	}
175 175
 
176 176
 	logCtx, err := lw.parseContext(string(parts[contextIndex]))
... ...
@@ -210,24 +211,24 @@ func (lw *logWriter) parseContext(input string) (logContext, error) {
210 210
 	for _, component := range components {
211 211
 		parts := strings.SplitN(component, "=", 2)
212 212
 		if len(parts) != 2 {
213
-			return logContext{}, fmt.Errorf("invalid context: %s", input)
213
+			return logContext{}, errors.Errorf("invalid context: %s", input)
214 214
 		}
215 215
 		context[parts[0]] = parts[1]
216 216
 	}
217 217
 
218 218
 	nodeID, ok := context["com.docker.swarm.node.id"]
219 219
 	if !ok {
220
-		return logContext{}, fmt.Errorf("missing node id in context: %s", input)
220
+		return logContext{}, errors.Errorf("missing node id in context: %s", input)
221 221
 	}
222 222
 
223 223
 	serviceID, ok := context["com.docker.swarm.service.id"]
224 224
 	if !ok {
225
-		return logContext{}, fmt.Errorf("missing service id in context: %s", input)
225
+		return logContext{}, errors.Errorf("missing service id in context: %s", input)
226 226
 	}
227 227
 
228 228
 	taskID, ok := context["com.docker.swarm.task.id"]
229 229
 	if !ok {
230
-		return logContext{}, fmt.Errorf("missing task id in context: %s", input)
230
+		return logContext{}, errors.Errorf("missing task id in context: %s", input)
231 231
 	}
232 232
 
233 233
 	return logContext{
... ...
@@ -1,7 +1,6 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"strconv"
7 6
 	"strings"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/opts"
13 13
 	runconfigopts "github.com/docker/docker/runconfig/opts"
14
+	"github.com/pkg/errors"
14 15
 	"github.com/spf13/pflag"
15 16
 )
16 17
 
... ...
@@ -32,7 +32,7 @@ func (d *PositiveDurationOpt) Set(s string) error {
32 32
 		return err
33 33
 	}
34 34
 	if *d.DurationOpt.value < 0 {
35
-		return fmt.Errorf("duration cannot be negative")
35
+		return errors.Errorf("duration cannot be negative")
36 36
 	}
37 37
 	return nil
38 38
 }
... ...
@@ -140,7 +140,7 @@ func (opts *placementPrefOpts) Set(value string) error {
140 140
 		return errors.New(`placement preference must be of the format "<strategy>=<arg>"`)
141 141
 	}
142 142
 	if fields[0] != "spread" {
143
-		return fmt.Errorf("unsupported placement preference %s (only spread is supported)", fields[0])
143
+		return errors.Errorf("unsupported placement preference %s (only spread is supported)", fields[0])
144 144
 	}
145 145
 
146 146
 	opts.prefs = append(opts.prefs, swarm.PlacementPreference{
... ...
@@ -268,7 +268,7 @@ func (opts *healthCheckOptions) toHealthConfig() (*container.HealthConfig, error
268 268
 		opts.retries != 0
269 269
 	if opts.noHealthcheck {
270 270
 		if haveHealthSettings {
271
-			return nil, fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck)
271
+			return nil, errors.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck)
272 272
 		}
273 273
 		healthConfig = &container.HealthConfig{Test: []string{"NONE"}}
274 274
 	} else if haveHealthSettings {
... ...
@@ -372,7 +372,7 @@ func (opts *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) {
372 372
 	switch opts.mode {
373 373
 	case "global":
374 374
 		if opts.replicas.Value() != nil {
375
-			return serviceMode, fmt.Errorf("replicas can only be used with replicated mode")
375
+			return serviceMode, errors.Errorf("replicas can only be used with replicated mode")
376 376
 		}
377 377
 
378 378
 		serviceMode.Global = &swarm.GlobalService{}
... ...
@@ -381,7 +381,7 @@ func (opts *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) {
381 381
 			Replicas: opts.replicas.Value(),
382 382
 		}
383 383
 	default:
384
-		return serviceMode, fmt.Errorf("Unknown mode: %s, only replicated and global supported", opts.mode)
384
+		return serviceMode, errors.Errorf("Unknown mode: %s, only replicated and global supported", opts.mode)
385 385
 	}
386 386
 	return serviceMode, nil
387 387
 }
... ...
@@ -1,12 +1,11 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"fmt"
5
-
6 4
 	"github.com/docker/docker/api/types"
7 5
 	"github.com/docker/docker/api/types/filters"
8 6
 	swarmtypes "github.com/docker/docker/api/types/swarm"
9 7
 	"github.com/docker/docker/client"
8
+	"github.com/pkg/errors"
10 9
 	"golang.org/x/net/context"
11 10
 )
12 11
 
... ...
@@ -18,7 +17,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
18 18
 
19 19
 	for _, secret := range requestedSecrets {
20 20
 		if _, exists := secretRefs[secret.File.Name]; exists {
21
-			return nil, fmt.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
21
+			return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
22 22
 		}
23 23
 		secretRef := new(swarmtypes.SecretReference)
24 24
 		*secretRef = *secret
... ...
@@ -47,7 +46,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
47 47
 	for _, ref := range secretRefs {
48 48
 		id, ok := foundSecrets[ref.SecretName]
49 49
 		if !ok {
50
-			return nil, fmt.Errorf("secret not found: %s", ref.SecretName)
50
+			return nil, errors.Errorf("secret not found: %s", ref.SecretName)
51 51
 		}
52 52
 
53 53
 		// set the id for the ref to properly assign in swarm
... ...
@@ -1,7 +1,6 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 
7 6
 	"golang.org/x/net/context"
... ...
@@ -15,6 +14,7 @@ import (
15 15
 	"github.com/docker/docker/cli/command/node"
16 16
 	"github.com/docker/docker/cli/command/task"
17 17
 	"github.com/docker/docker/opts"
18
+	"github.com/pkg/errors"
18 19
 	"github.com/spf13/cobra"
19 20
 )
20 21
 
... ...
@@ -89,7 +89,7 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error {
89 89
 		}
90 90
 		// If nothing has been found, return immediately.
91 91
 		if serviceCount == 0 {
92
-			return fmt.Errorf("no such services: %s", service)
92
+			return errors.Errorf("no such services: %s", service)
93 93
 		}
94 94
 	}
95 95
 
... ...
@@ -6,6 +6,7 @@ import (
6 6
 
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
9
+	"github.com/pkg/errors"
9 10
 	"github.com/spf13/cobra"
10 11
 	"golang.org/x/net/context"
11 12
 )
... ...
@@ -41,7 +42,7 @@ func runRemove(dockerCli *command.DockerCli, sids []string) error {
41 41
 		fmt.Fprintf(dockerCli.Out(), "%s\n", sid)
42 42
 	}
43 43
 	if len(errs) > 0 {
44
-		return fmt.Errorf(strings.Join(errs, "\n"))
44
+		return errors.Errorf(strings.Join(errs, "\n"))
45 45
 	}
46 46
 	return nil
47 47
 }
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types"
11 11
 	"github.com/docker/docker/cli"
12 12
 	"github.com/docker/docker/cli/command"
13
+	"github.com/pkg/errors"
13 14
 	"github.com/spf13/cobra"
14 15
 )
15 16
 
... ...
@@ -30,7 +31,7 @@ func scaleArgs(cmd *cobra.Command, args []string) error {
30 30
 	}
31 31
 	for _, arg := range args {
32 32
 		if parts := strings.SplitN(arg, "=", 2); len(parts) != 2 {
33
-			return fmt.Errorf(
33
+			return errors.Errorf(
34 34
 				"Invalid scale specifier '%s'.\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
35 35
 				arg,
36 36
 				cmd.CommandPath(),
... ...
@@ -43,7 +44,7 @@ func scaleArgs(cmd *cobra.Command, args []string) error {
43 43
 }
44 44
 
45 45
 func runScale(dockerCli *command.DockerCli, args []string) error {
46
-	var errors []string
46
+	var errs []string
47 47
 	for _, arg := range args {
48 48
 		parts := strings.SplitN(arg, "=", 2)
49 49
 		serviceID, scaleStr := parts[0], parts[1]
... ...
@@ -51,19 +52,19 @@ func runScale(dockerCli *command.DockerCli, args []string) error {
51 51
 		// validate input arg scale number
52 52
 		scale, err := strconv.ParseUint(scaleStr, 10, 64)
53 53
 		if err != nil {
54
-			errors = append(errors, fmt.Sprintf("%s: invalid replicas value %s: %v", serviceID, scaleStr, err))
54
+			errs = append(errs, fmt.Sprintf("%s: invalid replicas value %s: %v", serviceID, scaleStr, err))
55 55
 			continue
56 56
 		}
57 57
 
58 58
 		if err := runServiceScale(dockerCli, serviceID, scale); err != nil {
59
-			errors = append(errors, fmt.Sprintf("%s: %v", serviceID, err))
59
+			errs = append(errs, fmt.Sprintf("%s: %v", serviceID, err))
60 60
 		}
61 61
 	}
62 62
 
63
-	if len(errors) == 0 {
63
+	if len(errs) == 0 {
64 64
 		return nil
65 65
 	}
66
-	return fmt.Errorf(strings.Join(errors, "\n"))
66
+	return errors.Errorf(strings.Join(errs, "\n"))
67 67
 }
68 68
 
69 69
 func runServiceScale(dockerCli *command.DockerCli, serviceID string, scale uint64) error {
... ...
@@ -77,7 +78,7 @@ func runServiceScale(dockerCli *command.DockerCli, serviceID string, scale uint6
77 77
 
78 78
 	serviceMode := &service.Spec.Mode
79 79
 	if serviceMode.Replicated == nil {
80
-		return fmt.Errorf("scale can only be used with replicated mode")
80
+		return errors.Errorf("scale can only be used with replicated mode")
81 81
 	}
82 82
 
83 83
 	serviceMode.Replicated.Replicas = &scale
... ...
@@ -2,7 +2,6 @@ package service
2 2
 
3 3
 import (
4 4
 	"encoding/hex"
5
-	"fmt"
6 5
 
7 6
 	"github.com/Sirupsen/logrus"
8 7
 	"github.com/docker/distribution/reference"
... ...
@@ -72,7 +71,7 @@ func trustedResolveDigest(ctx context.Context, cli *command.DockerCli, ref refer
72 72
 	// Only get the tag if it's in the top level targets role or the releases delegation role
73 73
 	// ignore it if it's in any other delegation roles
74 74
 	if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
75
-		return nil, trust.NotaryError(repoInfo.Name.Name(), fmt.Errorf("No trust data for %s", reference.FamiliarString(ref)))
75
+		return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", reference.FamiliarString(ref)))
76 76
 	}
77 77
 
78 78
 	logrus.Debugf("retrieving target for %s role\n", t.Role)
... ...
@@ -1,7 +1,6 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"sort"
7 6
 	"strings"
... ...
@@ -19,6 +18,7 @@ import (
19 19
 	runconfigopts "github.com/docker/docker/runconfig/opts"
20 20
 	"github.com/docker/go-connections/nat"
21 21
 	shlex "github.com/flynn-archive/go-shlex"
22
+	"github.com/pkg/errors"
22 23
 	"github.com/spf13/cobra"
23 24
 	"github.com/spf13/pflag"
24 25
 	"golang.org/x/net/context"
... ...
@@ -136,7 +136,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, serviceID str
136 136
 			clientSideRollback = true
137 137
 			spec = service.PreviousSpec
138 138
 			if spec == nil {
139
-				return fmt.Errorf("service does not have a previous specification to roll back to")
139
+				return errors.Errorf("service does not have a previous specification to roll back to")
140 140
 			}
141 141
 		} else {
142 142
 			serverSideRollback = true
... ...
@@ -621,7 +621,7 @@ func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error {
621 621
 		values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value()
622 622
 		for _, mount := range values {
623 623
 			if _, ok := mountsByTarget[mount.Target]; ok {
624
-				return fmt.Errorf("duplicate mount target")
624
+				return errors.Errorf("duplicate mount target")
625 625
 			}
626 626
 			mountsByTarget[mount.Target] = mount
627 627
 		}
... ...
@@ -819,7 +819,7 @@ func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error
819 819
 	}
820 820
 
821 821
 	if serviceMode == nil || serviceMode.Replicated == nil {
822
-		return fmt.Errorf("replicas can only be used with replicated mode")
822
+		return errors.Errorf("replicas can only be used with replicated mode")
823 823
 	}
824 824
 	serviceMode.Replicated.Replicas = flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value()
825 825
 	return nil
... ...
@@ -908,7 +908,7 @@ func updateHealthcheck(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec)
908 908
 			}
909 909
 			return nil
910 910
 		}
911
-		return fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck)
911
+		return errors.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck)
912 912
 	}
913 913
 	if len(containerSpec.Healthcheck.Test) > 0 && containerSpec.Healthcheck.Test[0] == "NONE" {
914 914
 		containerSpec.Healthcheck.Test = nil
... ...
@@ -52,9 +52,9 @@ func runDeploy(dockerCli *command.DockerCli, opts deployOptions) error {
52 52
 
53 53
 	switch {
54 54
 	case opts.bundlefile == "" && opts.composefile == "":
55
-		return fmt.Errorf("Please specify either a bundle file (with --bundle-file) or a Compose file (with --compose-file).")
55
+		return errors.Errorf("Please specify either a bundle file (with --bundle-file) or a Compose file (with --compose-file).")
56 56
 	case opts.bundlefile != "" && opts.composefile != "":
57
-		return fmt.Errorf("You cannot specify both a bundle file and a Compose file.")
57
+		return errors.Errorf("You cannot specify both a bundle file and a Compose file.")
58 58
 	case opts.bundlefile != "":
59 59
 		return deployBundle(ctx, dockerCli, opts)
60 60
 	default:
... ...
@@ -28,7 +28,7 @@ func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deplo
28 28
 	config, err := loader.Load(configDetails)
29 29
 	if err != nil {
30 30
 		if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
31
-			return fmt.Errorf("Compose file contains unsupported options:\n\n%s\n",
31
+			return errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
32 32
 				propertyWarnings(fpe.Properties))
33 33
 		}
34 34
 
... ...
@@ -168,12 +168,12 @@ func validateExternalNetworks(
168 168
 		network, err := client.NetworkInspect(ctx, networkName, false)
169 169
 		if err != nil {
170 170
 			if dockerclient.IsErrNetworkNotFound(err) {
171
-				return fmt.Errorf("network %q is declared as external, but could not be found. You need to create the network before the stack is deployed (with overlay driver)", networkName)
171
+				return errors.Errorf("network %q is declared as external, but could not be found. You need to create the network before the stack is deployed (with overlay driver)", networkName)
172 172
 			}
173 173
 			return err
174 174
 		}
175 175
 		if network.Scope != "swarm" {
176
-			return fmt.Errorf("network %q is declared as external, but it is not in the right scope: %q instead of %q", networkName, network.Scope, "swarm")
176
+			return errors.Errorf("network %q is declared as external, but it is not in the right scope: %q instead of %q", networkName, network.Scope, "swarm")
177 177
 		}
178 178
 	}
179 179
 
... ...
@@ -12,6 +12,7 @@ import (
12 12
 	"github.com/docker/docker/cli/command"
13 13
 	"github.com/docker/docker/cli/compose/convert"
14 14
 	"github.com/docker/docker/client"
15
+	"github.com/pkg/errors"
15 16
 	"github.com/spf13/cobra"
16 17
 	"golang.org/x/net/context"
17 18
 )
... ...
@@ -100,7 +101,7 @@ func getStacks(
100 100
 		labels := service.Spec.Labels
101 101
 		name, ok := labels[convert.LabelNamespace]
102 102
 		if !ok {
103
-			return nil, fmt.Errorf("cannot get label %s for service %s",
103
+			return nil, errors.Errorf("cannot get label %s for service %s",
104 104
 				convert.LabelNamespace, service.ID)
105 105
 		}
106 106
 		ztack, ok := m[name]
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	"os"
7 7
 
8 8
 	"github.com/docker/docker/cli/command/bundlefile"
9
+	"github.com/pkg/errors"
9 10
 	"github.com/spf13/pflag"
10 11
 )
11 12
 
... ...
@@ -30,7 +31,7 @@ func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefil
30 30
 		path = defaultPath
31 31
 	}
32 32
 	if _, err := os.Stat(path); err != nil {
33
-		return nil, fmt.Errorf(
33
+		return nil, errors.Errorf(
34 34
 			"Bundle %s not found. Specify the path with --file",
35 35
 			path)
36 36
 	}
... ...
@@ -44,7 +45,7 @@ func loadBundlefile(stderr io.Writer, namespace string, path string) (*bundlefil
44 44
 
45 45
 	bundle, err := bundlefile.LoadFile(reader)
46 46
 	if err != nil {
47
-		return nil, fmt.Errorf("Error reading %s: %v\n", path, err)
47
+		return nil, errors.Errorf("Error reading %s: %v\n", path, err)
48 48
 	}
49 49
 	return bundle, err
50 50
 }
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"github.com/docker/docker/api/types/swarm"
8 8
 	"github.com/docker/docker/cli"
9 9
 	"github.com/docker/docker/cli/command"
10
+	"github.com/pkg/errors"
10 11
 	"github.com/spf13/cobra"
11 12
 	"golang.org/x/net/context"
12 13
 )
... ...
@@ -61,7 +62,7 @@ func runRemove(dockerCli *command.DockerCli, opts removeOptions) error {
61 61
 	hasError = removeNetworks(ctx, dockerCli, networks) || hasError
62 62
 
63 63
 	if hasError {
64
-		return fmt.Errorf("Failed to remove some resources")
64
+		return errors.Errorf("Failed to remove some resources")
65 65
 	}
66 66
 	return nil
67 67
 }
... ...
@@ -64,7 +64,7 @@ func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) erro
64 64
 		case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain:
65 65
 			req.Availability = availability
66 66
 		default:
67
-			return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
67
+			return errors.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
68 68
 		}
69 69
 	}
70 70
 
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker/cli/internal/test"
12 12
 	"github.com/docker/docker/pkg/testutil/assert"
13 13
 	"github.com/docker/docker/pkg/testutil/golden"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
... ...
@@ -26,28 +27,28 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
26 26
 		{
27 27
 			name: "init-failed",
28 28
 			swarmInitFunc: func() (string, error) {
29
-				return "", fmt.Errorf("error initializing the swarm")
29
+				return "", errors.Errorf("error initializing the swarm")
30 30
 			},
31 31
 			expectedError: "error initializing the swarm",
32 32
 		},
33 33
 		{
34 34
 			name: "init-failed-with-ip-choice",
35 35
 			swarmInitFunc: func() (string, error) {
36
-				return "", fmt.Errorf("could not choose an IP address to advertise")
36
+				return "", errors.Errorf("could not choose an IP address to advertise")
37 37
 			},
38 38
 			expectedError: "could not choose an IP address to advertise - specify one with --advertise-addr",
39 39
 		},
40 40
 		{
41 41
 			name: "swarm-inspect-after-init-failed",
42 42
 			swarmInspectFunc: func() (swarm.Swarm, error) {
43
-				return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
43
+				return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
44 44
 			},
45 45
 			expectedError: "error inspecting the swarm",
46 46
 		},
47 47
 		{
48 48
 			name: "node-inspect-after-init-failed",
49 49
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
50
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node")
50
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node")
51 51
 			},
52 52
 			expectedError: "error inspecting the node",
53 53
 		},
... ...
@@ -57,7 +58,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
57 57
 				flagAutolock: "true",
58 58
 			},
59 59
 			swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
60
-				return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting swarm unlock key")
60
+				return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting swarm unlock key")
61 61
 			},
62 62
 			expectedError: "could not fetch unlock key: error getting swarm unlock key",
63 63
 		},
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types/swarm"
10 10
 	"github.com/docker/docker/cli"
11 11
 	"github.com/docker/docker/cli/command"
12
+	"github.com/pkg/errors"
12 13
 	"github.com/spf13/cobra"
13 14
 	"github.com/spf13/pflag"
14 15
 )
... ...
@@ -61,7 +62,7 @@ func runJoin(dockerCli command.Cli, flags *pflag.FlagSet, opts joinOptions) erro
61 61
 		case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain:
62 62
 			req.Availability = availability
63 63
 		default:
64
-			return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
64
+			return errors.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability)
65 65
 		}
66 66
 	}
67 67
 
... ...
@@ -2,7 +2,6 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"strings"
8 7
 	"testing"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/cli/internal/test"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 func TestSwarmJoinErrors(t *testing.T) {
... ...
@@ -34,7 +34,7 @@ func TestSwarmJoinErrors(t *testing.T) {
34 34
 			name: "join-failed",
35 35
 			args: []string{"remote"},
36 36
 			swarmJoinFunc: func() error {
37
-				return fmt.Errorf("error joining the swarm")
37
+				return errors.Errorf("error joining the swarm")
38 38
 			},
39 39
 			expectedError: "error joining the swarm",
40 40
 		},
... ...
@@ -42,7 +42,7 @@ func TestSwarmJoinErrors(t *testing.T) {
42 42
 			name: "join-failed-on-init",
43 43
 			args: []string{"remote"},
44 44
 			infoFunc: func() (types.Info, error) {
45
-				return types.Info{}, fmt.Errorf("error asking for node info")
45
+				return types.Info{}, errors.Errorf("error asking for node info")
46 46
 			},
47 47
 			expectedError: "error asking for node info",
48 48
 		},
... ...
@@ -1,8 +1,8 @@
1 1
 package swarm
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
5
+	"github.com/pkg/errors"
6 6
 
7 7
 	"github.com/spf13/cobra"
8 8
 
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/api/types/swarm"
11 11
 	"github.com/docker/docker/cli/internal/test"
12
+	"github.com/pkg/errors"
12 13
 	// Import builders to get the builder function as package function
13 14
 	. "github.com/docker/docker/cli/internal/test/builders"
14 15
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -44,7 +45,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
44 44
 			name: "swarm-inspect-failed",
45 45
 			args: []string{"worker"},
46 46
 			swarmInspectFunc: func() (swarm.Swarm, error) {
47
-				return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
47
+				return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
48 48
 			},
49 49
 			expectedError: "error inspecting the swarm",
50 50
 		},
... ...
@@ -55,7 +56,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
55 55
 				flagRotate: "true",
56 56
 			},
57 57
 			swarmInspectFunc: func() (swarm.Swarm, error) {
58
-				return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
58
+				return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
59 59
 			},
60 60
 			expectedError: "error inspecting the swarm",
61 61
 		},
... ...
@@ -66,7 +67,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
66 66
 				flagRotate: "true",
67 67
 			},
68 68
 			swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
69
-				return fmt.Errorf("error updating the swarm")
69
+				return errors.Errorf("error updating the swarm")
70 70
 			},
71 71
 			expectedError: "error updating the swarm",
72 72
 		},
... ...
@@ -74,7 +75,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
74 74
 			name: "node-inspect-failed",
75 75
 			args: []string{"worker"},
76 76
 			nodeInspectFunc: func() (swarm.Node, []byte, error) {
77
-				return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting node")
77
+				return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node")
78 78
 			},
79 79
 			expectedError: "error inspecting node",
80 80
 		},
... ...
@@ -82,7 +83,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
82 82
 			name: "info-failed",
83 83
 			args: []string{"worker"},
84 84
 			infoFunc: func() (types.Info, error) {
85
-				return types.Info{}, fmt.Errorf("error asking for node info")
85
+				return types.Info{}, errors.Errorf("error asking for node info")
86 86
 			},
87 87
 			expectedError: "error asking for node info",
88 88
 		},
... ...
@@ -2,13 +2,13 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"strings"
8 7
 	"testing"
9 8
 
10 9
 	"github.com/docker/docker/cli/internal/test"
11 10
 	"github.com/docker/docker/pkg/testutil/assert"
11
+	"github.com/pkg/errors"
12 12
 )
13 13
 
14 14
 func TestSwarmLeaveErrors(t *testing.T) {
... ...
@@ -26,7 +26,7 @@ func TestSwarmLeaveErrors(t *testing.T) {
26 26
 		{
27 27
 			name: "leave-failed",
28 28
 			swarmLeaveFunc: func() error {
29
-				return fmt.Errorf("error leaving the swarm")
29
+				return errors.Errorf("error leaving the swarm")
30 30
 			},
31 31
 			expectedError: "error leaving the swarm",
32 32
 		},
... ...
@@ -2,13 +2,13 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"encoding/csv"
5
-	"errors"
6 5
 	"fmt"
7 6
 	"strings"
8 7
 	"time"
9 8
 
10 9
 	"github.com/docker/docker/api/types/swarm"
11 10
 	"github.com/docker/docker/opts"
11
+	"github.com/pkg/errors"
12 12
 	"github.com/spf13/pflag"
13 13
 )
14 14
 
... ...
@@ -139,7 +139,7 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) {
139 139
 		parts := strings.SplitN(field, "=", 2)
140 140
 
141 141
 		if len(parts) != 2 {
142
-			return nil, fmt.Errorf("invalid field '%s' must be a key=value pair", field)
142
+			return nil, errors.Errorf("invalid field '%s' must be a key=value pair", field)
143 143
 		}
144 144
 
145 145
 		key, value := parts[0], parts[1]
... ...
@@ -150,7 +150,7 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) {
150 150
 			if strings.ToLower(value) == string(swarm.ExternalCAProtocolCFSSL) {
151 151
 				externalCA.Protocol = swarm.ExternalCAProtocolCFSSL
152 152
 			} else {
153
-				return nil, fmt.Errorf("unrecognized external CA protocol %s", value)
153
+				return nil, errors.Errorf("unrecognized external CA protocol %s", value)
154 154
 			}
155 155
 		case "url":
156 156
 			hasURL = true
... ...
@@ -2,8 +2,8 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"bufio"
5
-	"errors"
6 5
 	"fmt"
6
+	"github.com/pkg/errors"
7 7
 	"io"
8 8
 	"strings"
9 9
 
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/api/types/swarm"
11 11
 	"github.com/docker/docker/cli/internal/test"
12
+	"github.com/pkg/errors"
12 13
 	// Import builders to get the builder function as package function
13 14
 	. "github.com/docker/docker/cli/internal/test/builders"
14 15
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -36,7 +37,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
36 36
 				flagRotate: "true",
37 37
 			},
38 38
 			swarmInspectFunc: func() (swarm.Swarm, error) {
39
-				return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
39
+				return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
40 40
 			},
41 41
 			expectedError: "error inspecting the swarm",
42 42
 		},
... ...
@@ -59,14 +60,14 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
59 59
 				return *Swarm(Autolock()), nil
60 60
 			},
61 61
 			swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
62
-				return fmt.Errorf("error updating the swarm")
62
+				return errors.Errorf("error updating the swarm")
63 63
 			},
64 64
 			expectedError: "error updating the swarm",
65 65
 		},
66 66
 		{
67 67
 			name: "swarm-get-unlock-key-failed",
68 68
 			swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
69
-				return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting unlock key")
69
+				return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key")
70 70
 			},
71 71
 			expectedError: "error getting unlock key",
72 72
 		},
... ...
@@ -2,7 +2,6 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"strings"
8 7
 	"testing"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/cli/internal/test"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 func TestSwarmUnlockErrors(t *testing.T) {
... ...
@@ -59,7 +59,7 @@ func TestSwarmUnlockErrors(t *testing.T) {
59 59
 				}, nil
60 60
 			},
61 61
 			swarmUnlockFunc: func(req swarm.UnlockRequest) error {
62
-				return fmt.Errorf("error unlocking the swarm")
62
+				return errors.Errorf("error unlocking the swarm")
63 63
 			},
64 64
 			expectedError: "error unlocking the swarm",
65 65
 		},
... ...
@@ -90,7 +90,7 @@ func TestSwarmUnlock(t *testing.T) {
90 90
 		},
91 91
 		swarmUnlockFunc: func(req swarm.UnlockRequest) error {
92 92
 			if req.UnlockKey != input {
93
-				return fmt.Errorf("Invalid unlock key")
93
+				return errors.Errorf("Invalid unlock key")
94 94
 			}
95 95
 			return nil
96 96
 		},
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types"
11 11
 	"github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/cli/internal/test"
13
+	"github.com/pkg/errors"
13 14
 	// Import builders to get the builder function as package function
14 15
 	. "github.com/docker/docker/cli/internal/test/builders"
15 16
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -37,7 +38,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
37 37
 				flagTaskHistoryLimit: "10",
38 38
 			},
39 39
 			swarmInspectFunc: func() (swarm.Swarm, error) {
40
-				return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm")
40
+				return swarm.Swarm{}, errors.Errorf("error inspecting the swarm")
41 41
 			},
42 42
 			expectedError: "error inspecting the swarm",
43 43
 		},
... ...
@@ -47,7 +48,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
47 47
 				flagTaskHistoryLimit: "10",
48 48
 			},
49 49
 			swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
50
-				return fmt.Errorf("error updating the swarm")
50
+				return errors.Errorf("error updating the swarm")
51 51
 			},
52 52
 			expectedError: "error updating the swarm",
53 53
 		},
... ...
@@ -60,7 +61,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
60 60
 				return *Swarm(), nil
61 61
 			},
62 62
 			swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) {
63
-				return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting unlock key")
63
+				return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key")
64 64
 			},
65 65
 			expectedError: "error getting unlock key",
66 66
 		},
... ...
@@ -108,33 +109,33 @@ func TestSwarmUpdate(t *testing.T) {
108 108
 			},
109 109
 			swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
110 110
 				if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 {
111
-					return fmt.Errorf("historyLimit not correctly set")
111
+					return errors.Errorf("historyLimit not correctly set")
112 112
 				}
113 113
 				heartbeatDuration, err := time.ParseDuration("10s")
114 114
 				if err != nil {
115 115
 					return err
116 116
 				}
117 117
 				if swarm.Dispatcher.HeartbeatPeriod != heartbeatDuration {
118
-					return fmt.Errorf("heartbeatPeriodLimit not correctly set")
118
+					return errors.Errorf("heartbeatPeriodLimit not correctly set")
119 119
 				}
120 120
 				certExpiryDuration, err := time.ParseDuration("20s")
121 121
 				if err != nil {
122 122
 					return err
123 123
 				}
124 124
 				if swarm.CAConfig.NodeCertExpiry != certExpiryDuration {
125
-					return fmt.Errorf("certExpiry not correctly set")
125
+					return errors.Errorf("certExpiry not correctly set")
126 126
 				}
127 127
 				if len(swarm.CAConfig.ExternalCAs) != 1 {
128
-					return fmt.Errorf("externalCA not correctly set")
128
+					return errors.Errorf("externalCA not correctly set")
129 129
 				}
130 130
 				if *swarm.Raft.KeepOldSnapshots != 10 {
131
-					return fmt.Errorf("keepOldSnapshots not correctly set")
131
+					return errors.Errorf("keepOldSnapshots not correctly set")
132 132
 				}
133 133
 				if swarm.Raft.SnapshotInterval != 100 {
134
-					return fmt.Errorf("snapshotInterval not correctly set")
134
+					return errors.Errorf("snapshotInterval not correctly set")
135 135
 				}
136 136
 				if !swarm.EncryptionConfig.AutoLockManagers {
137
-					return fmt.Errorf("autolock not correctly set")
137
+					return errors.Errorf("autolock not correctly set")
138 138
 				}
139 139
 				return nil
140 140
 			},
... ...
@@ -147,7 +148,7 @@ func TestSwarmUpdate(t *testing.T) {
147 147
 			},
148 148
 			swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error {
149 149
 				if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 {
150
-					return fmt.Errorf("historyLimit not correctly set")
150
+					return errors.Errorf("historyLimit not correctly set")
151 151
 				}
152 152
 				return nil
153 153
 			},
... ...
@@ -10,6 +10,7 @@ import (
10 10
 	"github.com/docker/docker/cli/command"
11 11
 	"github.com/docker/docker/cli/command/inspect"
12 12
 	apiclient "github.com/docker/docker/client"
13
+	"github.com/pkg/errors"
13 14
 	"github.com/spf13/cobra"
14 15
 )
15 16
 
... ...
@@ -48,7 +49,7 @@ func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error {
48 48
 	case "", "container", "image", "node", "network", "service", "volume", "task", "plugin":
49 49
 		elementSearcher = inspectAll(context.Background(), dockerCli, opts.size, opts.inspectType)
50 50
 	default:
51
-		return fmt.Errorf("%q is not a valid value for --type", opts.inspectType)
51
+		return errors.Errorf("%q is not a valid value for --type", opts.inspectType)
52 52
 	}
53 53
 	return inspect.Inspect(dockerCli.Out(), opts.ids, opts.format, elementSearcher)
54 54
 }
... ...
@@ -198,6 +199,6 @@ func inspectAll(ctx context.Context, dockerCli *command.DockerCli, getSize bool,
198 198
 			}
199 199
 			return v, raw, err
200 200
 		}
201
-		return nil, nil, fmt.Errorf("Error: No such object: %s", ref)
201
+		return nil, nil, errors.Errorf("Error: No such object: %s", ref)
202 202
 	}
203 203
 }
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"github.com/docker/docker/cli/command"
9 9
 	"github.com/docker/docker/opts"
10 10
 	runconfigopts "github.com/docker/docker/runconfig/opts"
11
+	"github.com/pkg/errors"
11 12
 	"github.com/spf13/cobra"
12 13
 	"golang.org/x/net/context"
13 14
 )
... ...
@@ -32,7 +33,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
32 32
 		RunE: func(cmd *cobra.Command, args []string) error {
33 33
 			if len(args) == 1 {
34 34
 				if opts.name != "" {
35
-					return fmt.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
35
+					return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
36 36
 				}
37 37
 				opts.name = args[0]
38 38
 			}
... ...
@@ -2,7 +2,6 @@ package volume
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"strings"
8 7
 	"testing"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	volumetypes "github.com/docker/docker/api/types/volume"
12 12
 	"github.com/docker/docker/cli/internal/test"
13 13
 	"github.com/docker/docker/pkg/testutil/assert"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 func TestVolumeCreateErrors(t *testing.T) {
... ...
@@ -33,7 +33,7 @@ func TestVolumeCreateErrors(t *testing.T) {
33 33
 		},
34 34
 		{
35 35
 			volumeCreateFunc: func(createBody volumetypes.VolumesCreateBody) (types.Volume, error) {
36
-				return types.Volume{}, fmt.Errorf("error creating volume")
36
+				return types.Volume{}, errors.Errorf("error creating volume")
37 37
 			},
38 38
 			expectedError: "error creating volume",
39 39
 		},
... ...
@@ -60,7 +60,7 @@ func TestVolumeCreateWithName(t *testing.T) {
60 60
 	cli := test.NewFakeCli(&fakeClient{
61 61
 		volumeCreateFunc: func(body volumetypes.VolumesCreateBody) (types.Volume, error) {
62 62
 			if body.Name != name {
63
-				return types.Volume{}, fmt.Errorf("expected name %q, got %q", name, body.Name)
63
+				return types.Volume{}, errors.Errorf("expected name %q, got %q", name, body.Name)
64 64
 			}
65 65
 			return types.Volume{
66 66
 				Name: body.Name,
... ...
@@ -98,16 +98,16 @@ func TestVolumeCreateWithFlags(t *testing.T) {
98 98
 	cli := test.NewFakeCli(&fakeClient{
99 99
 		volumeCreateFunc: func(body volumetypes.VolumesCreateBody) (types.Volume, error) {
100 100
 			if body.Name != "" {
101
-				return types.Volume{}, fmt.Errorf("expected empty name, got %q", body.Name)
101
+				return types.Volume{}, errors.Errorf("expected empty name, got %q", body.Name)
102 102
 			}
103 103
 			if body.Driver != expectedDriver {
104
-				return types.Volume{}, fmt.Errorf("expected driver %q, got %q", expectedDriver, body.Driver)
104
+				return types.Volume{}, errors.Errorf("expected driver %q, got %q", expectedDriver, body.Driver)
105 105
 			}
106 106
 			if !compareMap(body.DriverOpts, expectedOpts) {
107
-				return types.Volume{}, fmt.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts)
107
+				return types.Volume{}, errors.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts)
108 108
 			}
109 109
 			if !compareMap(body.Labels, expectedLabels) {
110
-				return types.Volume{}, fmt.Errorf("expected labels %v, got %v", expectedLabels, body.Labels)
110
+				return types.Volume{}, errors.Errorf("expected labels %v, got %v", expectedLabels, body.Labels)
111 111
 			}
112 112
 			return types.Volume{
113 113
 				Name: name,
... ...
@@ -8,6 +8,7 @@ import (
8 8
 
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/cli/internal/test"
11
+	"github.com/pkg/errors"
11 12
 	// Import builders to get the builder function as package function
12 13
 	. "github.com/docker/docker/cli/internal/test/builders"
13 14
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -27,7 +28,7 @@ func TestVolumeInspectErrors(t *testing.T) {
27 27
 		{
28 28
 			args: []string{"foo"},
29 29
 			volumeInspectFunc: func(volumeID string) (types.Volume, error) {
30
-				return types.Volume{}, fmt.Errorf("error while inspecting the volume")
30
+				return types.Volume{}, errors.Errorf("error while inspecting the volume")
31 31
 			},
32 32
 			expectedError: "error while inspecting the volume",
33 33
 		},
... ...
@@ -46,7 +47,7 @@ func TestVolumeInspectErrors(t *testing.T) {
46 46
 						Name: "foo",
47 47
 					}, nil
48 48
 				}
49
-				return types.Volume{}, fmt.Errorf("error while inspecting the volume")
49
+				return types.Volume{}, errors.Errorf("error while inspecting the volume")
50 50
 			},
51 51
 			expectedError: "error while inspecting the volume",
52 52
 		},
... ...
@@ -78,7 +79,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
78 78
 			args: []string{"foo"},
79 79
 			volumeInspectFunc: func(volumeID string) (types.Volume, error) {
80 80
 				if volumeID != "foo" {
81
-					return types.Volume{}, fmt.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID)
81
+					return types.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID)
82 82
 				}
83 83
 				return *Volume(), nil
84 84
 			},
... ...
@@ -2,7 +2,6 @@ package volume
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	volumetypes "github.com/docker/docker/api/types/volume"
12 12
 	"github.com/docker/docker/cli/config/configfile"
13 13
 	"github.com/docker/docker/cli/internal/test"
14
+	"github.com/pkg/errors"
14 15
 	// Import builders to get the builder function as package function
15 16
 	. "github.com/docker/docker/cli/internal/test/builders"
16 17
 	"github.com/docker/docker/pkg/testutil/assert"
... ...
@@ -30,7 +30,7 @@ func TestVolumeListErrors(t *testing.T) {
30 30
 		},
31 31
 		{
32 32
 			volumeListFunc: func(filter filters.Args) (volumetypes.VolumesListOKBody, error) {
33
-				return volumetypes.VolumesListOKBody{}, fmt.Errorf("error listing volumes")
33
+				return volumetypes.VolumesListOKBody{}, errors.Errorf("error listing volumes")
34 34
 			},
35 35
 			expectedError: "error listing volumes",
36 36
 		},
... ...
@@ -13,6 +13,7 @@ import (
13 13
 	"github.com/docker/docker/cli/internal/test"
14 14
 	"github.com/docker/docker/pkg/testutil/assert"
15 15
 	"github.com/docker/docker/pkg/testutil/golden"
16
+	"github.com/pkg/errors"
16 17
 )
17 18
 
18 19
 func TestVolumePruneErrors(t *testing.T) {
... ...
@@ -31,7 +32,7 @@ func TestVolumePruneErrors(t *testing.T) {
31 31
 				"force": "true",
32 32
 			},
33 33
 			volumePruneFunc: func(args filters.Args) (types.VolumesPruneReport, error) {
34
-				return types.VolumesPruneReport{}, fmt.Errorf("error pruning volumes")
34
+				return types.VolumesPruneReport{}, errors.Errorf("error pruning volumes")
35 35
 			},
36 36
 			expectedError: "error pruning volumes",
37 37
 		},
... ...
@@ -6,6 +6,7 @@ import (
6 6
 
7 7
 	"github.com/docker/docker/cli"
8 8
 	"github.com/docker/docker/cli/command"
9
+	"github.com/pkg/errors"
9 10
 	"github.com/spf13/cobra"
10 11
 	"golang.org/x/net/context"
11 12
 )
... ...
@@ -53,7 +54,7 @@ func runRemove(dockerCli command.Cli, opts *removeOptions) error {
53 53
 	}
54 54
 
55 55
 	if len(errs) > 0 {
56
-		return fmt.Errorf("%s", strings.Join(errs, "\n"))
56
+		return errors.Errorf("%s", strings.Join(errs, "\n"))
57 57
 	}
58 58
 	return nil
59 59
 }
... ...
@@ -2,12 +2,12 @@ package volume
2 2
 
3 3
 import (
4 4
 	"bytes"
5
-	"fmt"
6 5
 	"io/ioutil"
7 6
 	"testing"
8 7
 
9 8
 	"github.com/docker/docker/cli/internal/test"
10 9
 	"github.com/docker/docker/pkg/testutil/assert"
10
+	"github.com/pkg/errors"
11 11
 )
12 12
 
13 13
 func TestVolumeRemoveErrors(t *testing.T) {
... ...
@@ -22,7 +22,7 @@ func TestVolumeRemoveErrors(t *testing.T) {
22 22
 		{
23 23
 			args: []string{"nodeID"},
24 24
 			volumeRemoveFunc: func(volumeID string, force bool) error {
25
-				return fmt.Errorf("error removing the volume")
25
+				return errors.Errorf("error removing the volume")
26 26
 			},
27 27
 			expectedError: "error removing the volume",
28 28
 		},
... ...
@@ -261,7 +261,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
261 261
 	)
262 262
 	if healthcheck.Disable {
263 263
 		if len(healthcheck.Test) != 0 {
264
-			return nil, fmt.Errorf("test and disable can't be set at the same time")
264
+			return nil, errors.Errorf("test and disable can't be set at the same time")
265 265
 		}
266 266
 		return &container.HealthConfig{
267 267
 			Test: []string{"NONE"},
... ...
@@ -312,7 +312,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
312 312
 				MaxAttempts: &attempts,
313 313
 			}, nil
314 314
 		default:
315
-			return nil, fmt.Errorf("unknown restart policy: %s", restart)
315
+			return nil, errors.Errorf("unknown restart policy: %s", restart)
316 316
 		}
317 317
 	}
318 318
 	return &swarm.RestartPolicy{
... ...
@@ -418,13 +418,13 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
418 418
 	switch mode {
419 419
 	case "global":
420 420
 		if replicas != nil {
421
-			return serviceMode, fmt.Errorf("replicas can only be used with replicated mode")
421
+			return serviceMode, errors.Errorf("replicas can only be used with replicated mode")
422 422
 		}
423 423
 		serviceMode.Global = &swarm.GlobalService{}
424 424
 	case "replicated", "":
425 425
 		serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas}
426 426
 	default:
427
-		return serviceMode, fmt.Errorf("Unknown mode: %s", mode)
427
+		return serviceMode, errors.Errorf("Unknown mode: %s", mode)
428 428
 	}
429 429
 	return serviceMode, nil
430 430
 }
... ...
@@ -36,7 +36,7 @@ func ParseYAML(source []byte) (map[string]interface{}, error) {
36 36
 	}
37 37
 	cfgMap, ok := cfg.(map[interface{}]interface{})
38 38
 	if !ok {
39
-		return nil, fmt.Errorf("Top-level object must be a mapping")
39
+		return nil, errors.Errorf("Top-level object must be a mapping")
40 40
 	}
41 41
 	converted, err := convertToStringKeysRecursive(cfgMap, "")
42 42
 	if err != nil {
... ...
@@ -48,10 +48,10 @@ func ParseYAML(source []byte) (map[string]interface{}, error) {
48 48
 // Load reads a ConfigDetails and returns a fully loaded configuration
49 49
 func Load(configDetails types.ConfigDetails) (*types.Config, error) {
50 50
 	if len(configDetails.ConfigFiles) < 1 {
51
-		return nil, fmt.Errorf("No files specified")
51
+		return nil, errors.Errorf("No files specified")
52 52
 	}
53 53
 	if len(configDetails.ConfigFiles) > 1 {
54
-		return nil, fmt.Errorf("Multiple files are not yet supported")
54
+		return nil, errors.Errorf("Multiple files are not yet supported")
55 55
 	}
56 56
 
57 57
 	configDict := getConfigDict(configDetails)
... ...
@@ -310,7 +310,7 @@ func formatInvalidKeyError(keyPrefix string, key interface{}) error {
310 310
 	} else {
311 311
 		location = fmt.Sprintf("in %s", keyPrefix)
312 312
 	}
313
-	return fmt.Errorf("Non-string key %s: %#v", location, key)
313
+	return errors.Errorf("Non-string key %s: %#v", location, key)
314 314
 }
315 315
 
316 316
 // LoadServices produces a ServiceConfig map from a compose file Dict
... ...
@@ -415,7 +415,7 @@ func transformUlimits(data interface{}) (interface{}, error) {
415 415
 		ulimit.Hard = value["hard"].(int)
416 416
 		return ulimit, nil
417 417
 	default:
418
-		return data, fmt.Errorf("invalid type %T for ulimits", value)
418
+		return data, errors.Errorf("invalid type %T for ulimits", value)
419 419
 	}
420 420
 }
421 421
 
... ...
@@ -503,7 +503,7 @@ func transformMapStringString(data interface{}) (interface{}, error) {
503 503
 	case map[string]string:
504 504
 		return value, nil
505 505
 	default:
506
-		return data, fmt.Errorf("invalid type %T for map[string]string", value)
506
+		return data, errors.Errorf("invalid type %T for map[string]string", value)
507 507
 	}
508 508
 }
509 509
 
... ...
@@ -514,7 +514,7 @@ func transformExternal(data interface{}) (interface{}, error) {
514 514
 	case map[string]interface{}:
515 515
 		return map[string]interface{}{"external": true, "name": value["name"]}, nil
516 516
 	default:
517
-		return data, fmt.Errorf("invalid type %T for external", value)
517
+		return data, errors.Errorf("invalid type %T for external", value)
518 518
 	}
519 519
 }
520 520
 
... ...
@@ -542,12 +542,12 @@ func transformServicePort(data interface{}) (interface{}, error) {
542 542
 			case map[string]interface{}:
543 543
 				ports = append(ports, value)
544 544
 			default:
545
-				return data, fmt.Errorf("invalid type %T for port", value)
545
+				return data, errors.Errorf("invalid type %T for port", value)
546 546
 			}
547 547
 		}
548 548
 		return ports, nil
549 549
 	default:
550
-		return data, fmt.Errorf("invalid type %T for port", entries)
550
+		return data, errors.Errorf("invalid type %T for port", entries)
551 551
 	}
552 552
 }
553 553
 
... ...
@@ -558,7 +558,7 @@ func transformServiceSecret(data interface{}) (interface{}, error) {
558 558
 	case map[string]interface{}:
559 559
 		return data, nil
560 560
 	default:
561
-		return data, fmt.Errorf("invalid type %T for secret", value)
561
+		return data, errors.Errorf("invalid type %T for secret", value)
562 562
 	}
563 563
 }
564 564
 
... ...
@@ -569,7 +569,7 @@ func transformServiceVolumeConfig(data interface{}) (interface{}, error) {
569 569
 	case map[string]interface{}:
570 570
 		return data, nil
571 571
 	default:
572
-		return data, fmt.Errorf("invalid type %T for service volume", value)
572
+		return data, errors.Errorf("invalid type %T for service volume", value)
573 573
 	}
574 574
 
575 575
 }
... ...
@@ -601,7 +601,7 @@ func transformStringList(data interface{}) (interface{}, error) {
601 601
 	case []interface{}:
602 602
 		return value, nil
603 603
 	default:
604
-		return data, fmt.Errorf("invalid type %T for string list", value)
604
+		return data, errors.Errorf("invalid type %T for string list", value)
605 605
 	}
606 606
 }
607 607
 
... ...
@@ -625,7 +625,7 @@ func transformMappingOrList(mappingOrList interface{}, sep string, allowNil bool
625 625
 		}
626 626
 		return result
627 627
 	}
628
-	panic(fmt.Errorf("expected a map or a list, got %T: %#v", mappingOrList, mappingOrList))
628
+	panic(errors.Errorf("expected a map or a list, got %T: %#v", mappingOrList, mappingOrList))
629 629
 }
630 630
 
631 631
 func transformShellCommand(value interface{}) (interface{}, error) {
... ...
@@ -642,7 +642,7 @@ func transformHealthCheckTest(data interface{}) (interface{}, error) {
642 642
 	case []interface{}:
643 643
 		return value, nil
644 644
 	default:
645
-		return value, fmt.Errorf("invalid type %T for healthcheck.test", value)
645
+		return value, errors.Errorf("invalid type %T for healthcheck.test", value)
646 646
 	}
647 647
 }
648 648
 
... ...
@@ -653,7 +653,7 @@ func transformSize(value interface{}) (int64, error) {
653 653
 	case string:
654 654
 		return units.RAMInBytes(value)
655 655
 	}
656
-	panic(fmt.Errorf("invalid type for size %T", value))
656
+	panic(errors.Errorf("invalid type for size %T", value))
657 657
 }
658 658
 
659 659
 func toServicePortConfigs(value string) ([]interface{}, error) {
... ...
@@ -10,19 +10,20 @@ package schema
10 10
 import (
11 11
 	"bytes"
12 12
 	"compress/gzip"
13
-	"fmt"
14 13
 	"io"
15 14
 	"io/ioutil"
16 15
 	"os"
17 16
 	"path/filepath"
18 17
 	"strings"
19 18
 	"time"
19
+
20
+	"github.com/pkg/errors"
20 21
 )
21 22
 
22 23
 func bindataRead(data []byte, name string) ([]byte, error) {
23 24
 	gz, err := gzip.NewReader(bytes.NewBuffer(data))
24 25
 	if err != nil {
25
-		return nil, fmt.Errorf("Read %q: %v", name, err)
26
+		return nil, errors.Errorf("Read %q: %v", name, err)
26 27
 	}
27 28
 
28 29
 	var buf bytes.Buffer
... ...
@@ -30,7 +31,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
30 30
 	clErr := gz.Close()
31 31
 
32 32
 	if err != nil {
33
-		return nil, fmt.Errorf("Read %q: %v", name, err)
33
+		return nil, errors.Errorf("Read %q: %v", name, err)
34 34
 	}
35 35
 	if clErr != nil {
36 36
 		return nil, err
... ...
@@ -138,11 +139,11 @@ func Asset(name string) ([]byte, error) {
138 138
 	if f, ok := _bindata[cannonicalName]; ok {
139 139
 		a, err := f()
140 140
 		if err != nil {
141
-			return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
141
+			return nil, errors.Errorf("Asset %s can't read by error: %v", name, err)
142 142
 		}
143 143
 		return a.bytes, nil
144 144
 	}
145
-	return nil, fmt.Errorf("Asset %s not found", name)
145
+	return nil, errors.Errorf("Asset %s not found", name)
146 146
 }
147 147
 
148 148
 // MustAsset is like Asset but panics when Asset would return an error.
... ...
@@ -164,11 +165,11 @@ func AssetInfo(name string) (os.FileInfo, error) {
164 164
 	if f, ok := _bindata[cannonicalName]; ok {
165 165
 		a, err := f()
166 166
 		if err != nil {
167
-			return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
167
+			return nil, errors.Errorf("AssetInfo %s can't read by error: %v", name, err)
168 168
 		}
169 169
 		return a.info, nil
170 170
 	}
171
-	return nil, fmt.Errorf("AssetInfo %s not found", name)
171
+	return nil, errors.Errorf("AssetInfo %s not found", name)
172 172
 }
173 173
 
174 174
 // AssetNames returns the names of the assets.
... ...
@@ -208,12 +209,12 @@ func AssetDir(name string) ([]string, error) {
208 208
 		for _, p := range pathList {
209 209
 			node = node.Children[p]
210 210
 			if node == nil {
211
-				return nil, fmt.Errorf("Asset %s not found", name)
211
+				return nil, errors.Errorf("Asset %s not found", name)
212 212
 			}
213 213
 		}
214 214
 	}
215 215
 	if node.Func != nil {
216
-		return nil, fmt.Errorf("Asset %s not found", name)
216
+		return nil, errors.Errorf("Asset %s not found", name)
217 217
 	}
218 218
 	rv := make([]string, 0, len(node.Children))
219 219
 	for childName := range node.Children {
... ...
@@ -226,6 +227,7 @@ type bintree struct {
226 226
 	Func     func() (*asset, error)
227 227
 	Children map[string]*bintree
228 228
 }
229
+
229 230
 var _bintree = &bintree{nil, map[string]*bintree{
230 231
 	"data": &bintree{nil, map[string]*bintree{
231 232
 		"config_schema_v3.0.json": &bintree{dataConfig_schema_v30Json, map[string]*bintree{}},
... ...
@@ -280,4 +282,3 @@ func _filePath(dir, name string) string {
280 280
 	cannonicalName := strings.Replace(name, "\\", "/", -1)
281 281
 	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
282 282
 }
283
-
... ...
@@ -1,7 +1,6 @@
1 1
 package config
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"io"
6 5
 	"os"
7 6
 	"path/filepath"
... ...
@@ -9,6 +8,7 @@ import (
9 9
 	"github.com/docker/docker/api/types"
10 10
 	"github.com/docker/docker/cli/config/configfile"
11 11
 	"github.com/docker/docker/pkg/homedir"
12
+	"github.com/pkg/errors"
12 13
 )
13 14
 
14 15
 const (
... ...
@@ -84,18 +84,18 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
84 84
 	if _, err := os.Stat(configFile.Filename); err == nil {
85 85
 		file, err := os.Open(configFile.Filename)
86 86
 		if err != nil {
87
-			return &configFile, fmt.Errorf("%s - %v", configFile.Filename, err)
87
+			return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
88 88
 		}
89 89
 		defer file.Close()
90 90
 		err = configFile.LoadFromReader(file)
91 91
 		if err != nil {
92
-			err = fmt.Errorf("%s - %v", configFile.Filename, err)
92
+			err = errors.Errorf("%s - %v", configFile.Filename, err)
93 93
 		}
94 94
 		return &configFile, err
95 95
 	} else if !os.IsNotExist(err) {
96 96
 		// if file is there but we can't stat it for any reason other
97 97
 		// than it doesn't exist then stop
98
-		return &configFile, fmt.Errorf("%s - %v", configFile.Filename, err)
98
+		return &configFile, errors.Errorf("%s - %v", configFile.Filename, err)
99 99
 	}
100 100
 
101 101
 	// Can't find latest config file so check for the old one
... ...
@@ -105,12 +105,12 @@ func Load(configDir string) (*configfile.ConfigFile, error) {
105 105
 	}
106 106
 	file, err := os.Open(confFile)
107 107
 	if err != nil {
108
-		return &configFile, fmt.Errorf("%s - %v", confFile, err)
108
+		return &configFile, errors.Errorf("%s - %v", confFile, err)
109 109
 	}
110 110
 	defer file.Close()
111 111
 	err = configFile.LegacyLoadFromReader(file)
112 112
 	if err != nil {
113
-		return &configFile, fmt.Errorf("%s - %v", confFile, err)
113
+		return &configFile, errors.Errorf("%s - %v", confFile, err)
114 114
 	}
115 115
 
116 116
 	if configFile.HTTPHeaders == nil {
... ...
@@ -3,7 +3,6 @@ package configfile
3 3
 import (
4 4
 	"encoding/base64"
5 5
 	"encoding/json"
6
-	"fmt"
7 6
 	"io"
8 7
 	"io/ioutil"
9 8
 	"os"
... ...
@@ -11,6 +10,7 @@ import (
11 11
 	"strings"
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 const (
... ...
@@ -51,12 +51,12 @@ func (configFile *ConfigFile) LegacyLoadFromReader(configData io.Reader) error {
51 51
 	if err := json.Unmarshal(b, &configFile.AuthConfigs); err != nil {
52 52
 		arr := strings.Split(string(b), "\n")
53 53
 		if len(arr) < 2 {
54
-			return fmt.Errorf("The Auth config file is empty")
54
+			return errors.Errorf("The Auth config file is empty")
55 55
 		}
56 56
 		authConfig := types.AuthConfig{}
57 57
 		origAuth := strings.Split(arr[0], " = ")
58 58
 		if len(origAuth) != 2 {
59
-			return fmt.Errorf("Invalid Auth config file")
59
+			return errors.Errorf("Invalid Auth config file")
60 60
 		}
61 61
 		authConfig.Username, authConfig.Password, err = decodeAuth(origAuth[1])
62 62
 		if err != nil {
... ...
@@ -135,7 +135,7 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
135 135
 // Save encodes and writes out all the authorization information
136 136
 func (configFile *ConfigFile) Save() error {
137 137
 	if configFile.Filename == "" {
138
-		return fmt.Errorf("Can't save config with empty filename")
138
+		return errors.Errorf("Can't save config with empty filename")
139 139
 	}
140 140
 
141 141
 	if err := os.MkdirAll(filepath.Dir(configFile.Filename), 0700); err != nil {
... ...
@@ -176,11 +176,11 @@ func decodeAuth(authStr string) (string, string, error) {
176 176
 		return "", "", err
177 177
 	}
178 178
 	if n > decLen {
179
-		return "", "", fmt.Errorf("Something went wrong decoding auth config")
179
+		return "", "", errors.Errorf("Something went wrong decoding auth config")
180 180
 	}
181 181
 	arr := strings.SplitN(string(decoded), ":", 2)
182 182
 	if len(arr) != 2 {
183
-		return "", "", fmt.Errorf("Invalid auth configuration file")
183
+		return "", "", errors.Errorf("Invalid auth configuration file")
184 184
 	}
185 185
 	password := strings.Trim(arr[1], "\x00")
186 186
 	return arr[0], password, nil
... ...
@@ -11,6 +11,7 @@ import (
11 11
 	"github.com/docker/docker-credential-helpers/client"
12 12
 	"github.com/docker/docker-credential-helpers/credentials"
13 13
 	"github.com/docker/docker/api/types"
14
+	"github.com/pkg/errors"
14 15
 )
15 16
 
16 17
 const (
... ...
@@ -20,7 +21,7 @@ const (
20 20
 	missingCredsAddress  = "https://missing.docker.io/v1"
21 21
 )
22 22
 
23
-var errCommandExited = fmt.Errorf("exited 1")
23
+var errCommandExited = errors.Errorf("exited 1")
24 24
 
25 25
 // mockCommand simulates interactions between the docker client and a remote
26 26
 // credentials helper.
... ...
@@ -1,9 +1,9 @@
1 1
 package cli
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"strings"
6 5
 
6
+	"github.com/pkg/errors"
7 7
 	"github.com/spf13/cobra"
8 8
 )
9 9
 
... ...
@@ -14,10 +14,10 @@ func NoArgs(cmd *cobra.Command, args []string) error {
14 14
 	}
15 15
 
16 16
 	if cmd.HasSubCommands() {
17
-		return fmt.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n"))
17
+		return errors.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n"))
18 18
 	}
19 19
 
20
-	return fmt.Errorf(
20
+	return errors.Errorf(
21 21
 		"\"%s\" accepts no argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
22 22
 		cmd.CommandPath(),
23 23
 		cmd.CommandPath(),
... ...
@@ -32,7 +32,7 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
32 32
 		if len(args) >= min {
33 33
 			return nil
34 34
 		}
35
-		return fmt.Errorf(
35
+		return errors.Errorf(
36 36
 			"\"%s\" requires at least %d argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
37 37
 			cmd.CommandPath(),
38 38
 			min,
... ...
@@ -49,7 +49,7 @@ func RequiresMaxArgs(max int) cobra.PositionalArgs {
49 49
 		if len(args) <= max {
50 50
 			return nil
51 51
 		}
52
-		return fmt.Errorf(
52
+		return errors.Errorf(
53 53
 			"\"%s\" requires at most %d argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
54 54
 			cmd.CommandPath(),
55 55
 			max,
... ...
@@ -66,7 +66,7 @@ func RequiresRangeArgs(min int, max int) cobra.PositionalArgs {
66 66
 		if len(args) >= min && len(args) <= max {
67 67
 			return nil
68 68
 		}
69
-		return fmt.Errorf(
69
+		return errors.Errorf(
70 70
 			"\"%s\" requires at least %d and at most %d argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
71 71
 			cmd.CommandPath(),
72 72
 			min,
... ...
@@ -84,7 +84,7 @@ func ExactArgs(number int) cobra.PositionalArgs {
84 84
 		if len(args) == number {
85 85
 			return nil
86 86
 		}
87
-		return fmt.Errorf(
87
+		return errors.Errorf(
88 88
 			"\"%s\" requires exactly %d argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
89 89
 			cmd.CommandPath(),
90 90
 			number,
... ...
@@ -2,7 +2,6 @@ package trust
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"fmt"
6 5
 	"net"
7 6
 	"net/http"
8 7
 	"net/url"
... ...
@@ -29,6 +28,7 @@ import (
29 29
 	"github.com/docker/notary/trustpinning"
30 30
 	"github.com/docker/notary/tuf/data"
31 31
 	"github.com/docker/notary/tuf/signed"
32
+	"github.com/pkg/errors"
32 33
 )
33 34
 
34 35
 var (
... ...
@@ -57,7 +57,7 @@ func Server(index *registrytypes.IndexInfo) (string, error) {
57 57
 	if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" {
58 58
 		urlObj, err := url.Parse(s)
59 59
 		if err != nil || urlObj.Scheme != "https" {
60
-			return "", fmt.Errorf("valid https URL required for trust server, got %s", s)
60
+			return "", errors.Errorf("valid https URL required for trust server, got %s", s)
61 61
 		}
62 62
 
63 63
 		return s, nil
... ...
@@ -205,27 +205,27 @@ func NotaryError(repoName string, err error) error {
205 205
 	switch err.(type) {
206 206
 	case *json.SyntaxError:
207 207
 		logrus.Debugf("Notary syntax error: %s", err)
208
-		return fmt.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName)
208
+		return errors.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName)
209 209
 	case signed.ErrExpired:
210
-		return fmt.Errorf("Error: remote repository %s out-of-date: %v", repoName, err)
210
+		return errors.Errorf("Error: remote repository %s out-of-date: %v", repoName, err)
211 211
 	case trustmanager.ErrKeyNotFound:
212
-		return fmt.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err)
212
+		return errors.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err)
213 213
 	case storage.NetworkError:
214
-		return fmt.Errorf("Error: error contacting notary server: %v", err)
214
+		return errors.Errorf("Error: error contacting notary server: %v", err)
215 215
 	case storage.ErrMetaNotFound:
216
-		return fmt.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err)
216
+		return errors.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err)
217 217
 	case trustpinning.ErrRootRotationFail, trustpinning.ErrValidationFail, signed.ErrInvalidKeyType:
218
-		return fmt.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err)
218
+		return errors.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err)
219 219
 	case signed.ErrNoKeys:
220
-		return fmt.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err)
220
+		return errors.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err)
221 221
 	case signed.ErrLowVersion:
222
-		return fmt.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err)
222
+		return errors.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err)
223 223
 	case signed.ErrRoleThreshold:
224
-		return fmt.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err)
224
+		return errors.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err)
225 225
 	case client.ErrRepositoryNotExist:
226
-		return fmt.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err)
226
+		return errors.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err)
227 227
 	case signed.ErrInsufficientSignatures:
228
-		return fmt.Errorf("Error: could not produce valid signature for %s.  If Yubikey was used, was touch input provided?: %v", repoName, err)
228
+		return errors.Errorf("Error: could not produce valid signature for %s.  If Yubikey was used, was touch input provided?: %v", repoName, err)
229 229
 	}
230 230
 
231 231
 	return err