Browse code

Remove redundant format

Signed-off-by: Ke Li <kel@splunk.com>

Add missing changes

Signed-off-by: Ke Li <kel@splunk.com>

User errors.New to create error

Signed-off-by: Ke Li <kel@splunk.com>

Ke Li authored on 2016/12/25 15:37:31
Showing 20 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 package httputils
2 2
 
3 3
 import (
4
-	"fmt"
4
+	"errors"
5 5
 	"net/http"
6 6
 	"path/filepath"
7 7
 	"strconv"
... ...
@@ -61,9 +61,9 @@ func ArchiveFormValues(r *http.Request, vars map[string]string) (ArchiveOptions,
61 61
 
62 62
 	switch {
63 63
 	case name == "":
64
-		return ArchiveOptions{}, fmt.Errorf("bad parameter: 'name' cannot be empty")
64
+		return ArchiveOptions{}, errors.New("bad parameter: 'name' cannot be empty")
65 65
 	case path == "":
66
-		return ArchiveOptions{}, fmt.Errorf("bad parameter: 'path' cannot be empty")
66
+		return ArchiveOptions{}, errors.New("bad parameter: 'path' cannot be empty")
67 67
 	}
68 68
 
69 69
 	return ArchiveOptions{name, path}, nil
... ...
@@ -167,7 +167,7 @@ func (bf *BFlags) Parse() error {
167 167
 			flag.Value = value
168 168
 
169 169
 		default:
170
-			panic(fmt.Errorf("No idea what kind of flag we have! Should never get here!"))
170
+			panic("No idea what kind of flag we have! Should never get here!")
171 171
 		}
172 172
 
173 173
 	}
... ...
@@ -35,10 +35,10 @@ func TestBuilderFlags(t *testing.T) {
35 35
 	}
36 36
 
37 37
 	if flStr1.IsUsed() == true {
38
-		t.Fatalf("Test3 - str1 was not used!")
38
+		t.Fatal("Test3 - str1 was not used!")
39 39
 	}
40 40
 	if flBool1.IsUsed() == true {
41
-		t.Fatalf("Test3 - bool1 was not used!")
41
+		t.Fatal("Test3 - bool1 was not used!")
42 42
 	}
43 43
 
44 44
 	// ---
... ...
@@ -53,16 +53,16 @@ func TestBuilderFlags(t *testing.T) {
53 53
 	}
54 54
 
55 55
 	if flStr1.Value != "HI" {
56
-		t.Fatalf("Str1 was supposed to default to: HI")
56
+		t.Fatal("Str1 was supposed to default to: HI")
57 57
 	}
58 58
 	if flBool1.IsTrue() {
59
-		t.Fatalf("Bool1 was supposed to default to: false")
59
+		t.Fatal("Bool1 was supposed to default to: false")
60 60
 	}
61 61
 	if flStr1.IsUsed() == true {
62
-		t.Fatalf("Str1 was not used!")
62
+		t.Fatal("Str1 was not used!")
63 63
 	}
64 64
 	if flBool1.IsUsed() == true {
65
-		t.Fatalf("Bool1 was not used!")
65
+		t.Fatal("Bool1 was not used!")
66 66
 	}
67 67
 
68 68
 	// ---
... ...
@@ -116,7 +116,7 @@ func TestBuilderFlags(t *testing.T) {
116 116
 	}
117 117
 
118 118
 	if !flBool1.IsTrue() {
119
-		t.Fatalf("Test-b1 Bool1 was supposed to be true")
119
+		t.Fatal("Test-b1 Bool1 was supposed to be true")
120 120
 	}
121 121
 
122 122
 	// ---
... ...
@@ -144,7 +144,7 @@ func TestBuilderFlags(t *testing.T) {
144 144
 	}
145 145
 
146 146
 	if flBool1.IsTrue() {
147
-		t.Fatalf("Test-b3 Bool1 was supposed to be false")
147
+		t.Fatal("Test-b3 Bool1 was supposed to be false")
148 148
 	}
149 149
 
150 150
 	// ---
... ...
@@ -257,8 +257,8 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
257 257
 		select {
258 258
 		case <-b.clientCtx.Done():
259 259
 			logrus.Debug("Builder: build cancelled!")
260
-			fmt.Fprintf(b.Stdout, "Build cancelled")
261
-			return "", fmt.Errorf("Build cancelled")
260
+			fmt.Fprint(b.Stdout, "Build cancelled")
261
+			return "", errors.New("Build cancelled")
262 262
 		default:
263 263
 			// Not cancelled yet, keep going...
264 264
 		}
... ...
@@ -291,7 +291,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
291 291
 	}
292 292
 
293 293
 	if b.image == "" {
294
-		return "", fmt.Errorf("No image was generated. Is your Dockerfile empty?")
294
+		return "", errors.New("No image was generated. Is your Dockerfile empty?")
295 295
 	}
296 296
 
297 297
 	if b.options.Squash {
... ...
@@ -8,6 +8,7 @@ package dockerfile
8 8
 // package.
9 9
 
10 10
 import (
11
+	"errors"
11 12
 	"fmt"
12 13
 	"regexp"
13 14
 	"runtime"
... ...
@@ -211,7 +212,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
211 211
 	// Windows cannot support a container with no base image.
212 212
 	if name == api.NoBaseImageSpecifier {
213 213
 		if runtime.GOOS == "windows" {
214
-			return fmt.Errorf("Windows does not support FROM scratch")
214
+			return errors.New("Windows does not support FROM scratch")
215 215
 		}
216 216
 		b.image = ""
217 217
 		b.noBaseImage = true
... ...
@@ -254,7 +255,7 @@ func onbuild(b *Builder, args []string, attributes map[string]bool, original str
254 254
 	triggerInstruction := strings.ToUpper(strings.TrimSpace(args[0]))
255 255
 	switch triggerInstruction {
256 256
 	case "ONBUILD":
257
-		return fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
257
+		return errors.New("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
258 258
 	case "MAINTAINER", "FROM":
259 259
 		return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", triggerInstruction)
260 260
 	}
... ...
@@ -331,7 +332,7 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
331 331
 //
332 332
 func run(b *Builder, args []string, attributes map[string]bool, original string) error {
333 333
 	if b.image == "" && !b.noBaseImage {
334
-		return fmt.Errorf("Please provide a source image with `from` prior to run")
334
+		return errors.New("Please provide a source image with `from` prior to run")
335 335
 	}
336 336
 
337 337
 	if err := b.flags.Parse(); err != nil {
... ...
@@ -499,7 +500,7 @@ func healthcheck(b *Builder, args []string, attributes map[string]bool, original
499 499
 	args = args[1:]
500 500
 	if typ == "NONE" {
501 501
 		if len(args) != 0 {
502
-			return fmt.Errorf("HEALTHCHECK NONE takes no arguments")
502
+			return errors.New("HEALTHCHECK NONE takes no arguments")
503 503
 		}
504 504
 		test := strslice.StrSlice{typ}
505 505
 		b.runConfig.Healthcheck = &container.HealthConfig{
... ...
@@ -527,7 +528,7 @@ func healthcheck(b *Builder, args []string, attributes map[string]bool, original
527 527
 		case "CMD":
528 528
 			cmdSlice := handleJSONArgs(args, attributes)
529 529
 			if len(cmdSlice) == 0 {
530
-				return fmt.Errorf("Missing command after HEALTHCHECK CMD")
530
+				return errors.New("Missing command after HEALTHCHECK CMD")
531 531
 			}
532 532
 
533 533
 			if !attributes["json"] {
... ...
@@ -688,7 +689,7 @@ func volume(b *Builder, args []string, attributes map[string]bool, original stri
688 688
 	for _, v := range args {
689 689
 		v = strings.TrimSpace(v)
690 690
 		if v == "" {
691
-			return fmt.Errorf("VOLUME specified can not be an empty string")
691
+			return errors.New("VOLUME specified can not be an empty string")
692 692
 		}
693 693
 		b.runConfig.Volumes[v] = struct{}{}
694 694
 	}
... ...
@@ -196,7 +196,7 @@ func TestFrom(t *testing.T) {
196 196
 
197 197
 	if runtime.GOOS == "windows" {
198 198
 		if err == nil {
199
-			t.Fatalf("Error not set on Windows")
199
+			t.Fatal("Error not set on Windows")
200 200
 		}
201 201
 
202 202
 		expectedError := "Windows does not support FROM scratch"
... ...
@@ -231,7 +231,7 @@ func TestOnbuildIllegalTriggers(t *testing.T) {
231 231
 		err := onbuild(b, []string{trigger.command}, nil, "")
232 232
 
233 233
 		if err == nil {
234
-			t.Fatalf("Error should not be nil")
234
+			t.Fatal("Error should not be nil")
235 235
 		}
236 236
 
237 237
 		if !strings.Contains(err.Error(), trigger.expectedError) {
... ...
@@ -301,7 +301,7 @@ func TestCmd(t *testing.T) {
301 301
 	}
302 302
 
303 303
 	if !b.cmdSet {
304
-		t.Fatalf("Command should be marked as set")
304
+		t.Fatal("Command should be marked as set")
305 305
 	}
306 306
 }
307 307
 
... ...
@@ -365,7 +365,7 @@ func TestEntrypoint(t *testing.T) {
365 365
 	}
366 366
 
367 367
 	if b.runConfig.Entrypoint == nil {
368
-		t.Fatalf("Entrypoint should be set")
368
+		t.Fatal("Entrypoint should be set")
369 369
 	}
370 370
 
371 371
 	var expectedEntrypoint strslice.StrSlice
... ...
@@ -391,7 +391,7 @@ func TestExpose(t *testing.T) {
391 391
 	}
392 392
 
393 393
 	if b.runConfig.ExposedPorts == nil {
394
-		t.Fatalf("ExposedPorts should be set")
394
+		t.Fatal("ExposedPorts should be set")
395 395
 	}
396 396
 
397 397
 	if len(b.runConfig.ExposedPorts) != 1 {
... ...
@@ -433,7 +433,7 @@ func TestVolume(t *testing.T) {
433 433
 	}
434 434
 
435 435
 	if b.runConfig.Volumes == nil {
436
-		t.Fatalf("Volumes should be set")
436
+		t.Fatal("Volumes should be set")
437 437
 	}
438 438
 
439 439
 	if len(b.runConfig.Volumes) != 1 {
... ...
@@ -506,7 +506,7 @@ func TestShell(t *testing.T) {
506 506
 	}
507 507
 
508 508
 	if b.runConfig.Shell == nil {
509
-		t.Fatalf("Shell should be set")
509
+		t.Fatal("Shell should be set")
510 510
 	}
511 511
 
512 512
 	expectedShell := strslice.StrSlice([]string{shellCmd})
... ...
@@ -20,6 +20,7 @@
20 20
 package dockerfile
21 21
 
22 22
 import (
23
+	"errors"
23 24
 	"fmt"
24 25
 	"strings"
25 26
 
... ...
@@ -115,7 +116,7 @@ func (b *Builder) dispatch(stepN int, stepTotal int, ast *parser.Node) error {
115 115
 
116 116
 	if cmd == "onbuild" {
117 117
 		if ast.Next == nil {
118
-			return fmt.Errorf("ONBUILD requires at least one argument")
118
+			return errors.New("ONBUILD requires at least one argument")
119 119
 		}
120 120
 		ast = ast.Next.Children[0]
121 121
 		strList = append(strList, ast.Value)
... ...
@@ -222,7 +223,7 @@ func (b *Builder) checkDispatch(ast *parser.Node, onbuild bool) error {
222 222
 	// least one argument
223 223
 	if upperCasedCmd == "ONBUILD" {
224 224
 		if ast.Next == nil {
225
-			return fmt.Errorf("ONBUILD requires at least one argument")
225
+			return errors.New("ONBUILD requires at least one argument")
226 226
 		}
227 227
 	}
228 228
 
... ...
@@ -230,7 +231,7 @@ func (b *Builder) checkDispatch(ast *parser.Node, onbuild bool) error {
230 230
 	if onbuild {
231 231
 		switch upperCasedCmd {
232 232
 		case "ONBUILD":
233
-			return fmt.Errorf("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
233
+			return errors.New("Chaining ONBUILD via `ONBUILD ONBUILD` isn't allowed")
234 234
 		case "MAINTAINER", "FROM":
235 235
 			return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", upperCasedCmd)
236 236
 		}
... ...
@@ -43,7 +43,7 @@ func (b *Builder) commit(id string, autoCmd strslice.StrSlice, comment string) e
43 43
 		return nil
44 44
 	}
45 45
 	if b.image == "" && !b.noBaseImage {
46
-		return fmt.Errorf("Please provide a source image with `from` prior to commit")
46
+		return errors.New("Please provide a source image with `from` prior to commit")
47 47
 	}
48 48
 	b.runConfig.Image = b.image
49 49
 
... ...
@@ -137,7 +137,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
137 137
 	}
138 138
 
139 139
 	if len(infos) == 0 {
140
-		return fmt.Errorf("No source files were specified")
140
+		return errors.New("No source files were specified")
141 141
 	}
142 142
 	if len(infos) > 1 && !strings.HasSuffix(dest, string(os.PathSeparator)) {
143 143
 		return fmt.Errorf("When using %s with more than one source file, the destination must be a directory and end with a /", cmdName)
... ...
@@ -456,7 +456,7 @@ func (b *Builder) probeCache() (bool, error) {
456 456
 		return false, nil
457 457
 	}
458 458
 
459
-	fmt.Fprintf(b.Stdout, " ---> Using cache\n")
459
+	fmt.Fprint(b.Stdout, " ---> Using cache\n")
460 460
 	logrus.Debugf("[BUILDER] Use cached version: %s", b.runConfig.Cmd)
461 461
 	b.image = string(cache)
462 462
 
... ...
@@ -465,7 +465,7 @@ func (b *Builder) probeCache() (bool, error) {
465 465
 
466 466
 func (b *Builder) create() (string, error) {
467 467
 	if b.image == "" && !b.noBaseImage {
468
-		return "", fmt.Errorf("Please provide a source image with `from` prior to run")
468
+		return "", errors.New("Please provide a source image with `from` prior to run")
469 469
 	}
470 470
 	b.runConfig.Image = b.image
471 471
 
... ...
@@ -121,35 +121,35 @@ func TestGetEnv(t *testing.T) {
121 121
 
122 122
 	sw.envs = []string{}
123 123
 	if sw.getEnv("foo") != "" {
124
-		t.Fatalf("2 - 'foo' should map to ''")
124
+		t.Fatal("2 - 'foo' should map to ''")
125 125
 	}
126 126
 
127 127
 	sw.envs = []string{"foo"}
128 128
 	if sw.getEnv("foo") != "" {
129
-		t.Fatalf("3 - 'foo' should map to ''")
129
+		t.Fatal("3 - 'foo' should map to ''")
130 130
 	}
131 131
 
132 132
 	sw.envs = []string{"foo="}
133 133
 	if sw.getEnv("foo") != "" {
134
-		t.Fatalf("4 - 'foo' should map to ''")
134
+		t.Fatal("4 - 'foo' should map to ''")
135 135
 	}
136 136
 
137 137
 	sw.envs = []string{"foo=bar"}
138 138
 	if sw.getEnv("foo") != "bar" {
139
-		t.Fatalf("5 - 'foo' should map to 'bar'")
139
+		t.Fatal("5 - 'foo' should map to 'bar'")
140 140
 	}
141 141
 
142 142
 	sw.envs = []string{"foo=bar", "car=hat"}
143 143
 	if sw.getEnv("foo") != "bar" {
144
-		t.Fatalf("6 - 'foo' should map to 'bar'")
144
+		t.Fatal("6 - 'foo' should map to 'bar'")
145 145
 	}
146 146
 	if sw.getEnv("car") != "hat" {
147
-		t.Fatalf("7 - 'car' should map to 'hat'")
147
+		t.Fatal("7 - 'car' should map to 'hat'")
148 148
 	}
149 149
 
150 150
 	// Make sure we grab the first 'car' in the list
151 151
 	sw.envs = []string{"foo=bar", "car=hat", "car=bike"}
152 152
 	if sw.getEnv("car") != "hat" {
153
-		t.Fatalf("8 - 'car' should map to 'hat'")
153
+		t.Fatal("8 - 'car' should map to 'hat'")
154 154
 	}
155 155
 }
... ...
@@ -91,16 +91,16 @@ const (
91 91
 )
92 92
 
93 93
 // errNoSwarm is returned on leaving a cluster that was never initialized
94
-var errNoSwarm = fmt.Errorf("This node is not part of a swarm")
94
+var errNoSwarm = errors.New("This node is not part of a swarm")
95 95
 
96 96
 // errSwarmExists is returned on initialize or join request for a cluster that has already been activated
97
-var errSwarmExists = fmt.Errorf("This node is already part of a swarm. Use \"docker swarm leave\" to leave this swarm and join another one.")
97
+var errSwarmExists = errors.New("This node is already part of a swarm. Use \"docker swarm leave\" to leave this swarm and join another one.")
98 98
 
99 99
 // errSwarmJoinTimeoutReached is returned when cluster join could not complete before timeout was reached.
100
-var errSwarmJoinTimeoutReached = fmt.Errorf("Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the \"docker info\" command to see the current swarm status of your node.")
100
+var errSwarmJoinTimeoutReached = errors.New("Timeout was reached before node was joined. The attempt to join the swarm will continue in the background. Use the \"docker info\" command to see the current swarm status of your node.")
101 101
 
102 102
 // errSwarmLocked is returned if the swarm is encrypted and needs a key to unlock it.
103
-var errSwarmLocked = fmt.Errorf("Swarm is encrypted and needs to be unlocked before it can be used. Please use \"docker swarm unlock\" to unlock it.")
103
+var errSwarmLocked = errors.New("Swarm is encrypted and needs to be unlocked before it can be used. Please use \"docker swarm unlock\" to unlock it.")
104 104
 
105 105
 // errSwarmCertificatesExpired is returned if docker was not started for the whole validity period and they had no chance to renew automatically.
106 106
 var errSwarmCertificatesExpired = errors.New("Swarm certificates have expired. To replace them, leave the swarm and join again.")
... ...
@@ -521,7 +521,7 @@ func (c *Cluster) Leave(force bool) error {
521 521
 					if isLastManager(reachable, unreachable) {
522 522
 						msg += "Removing the last manager erases all current state of the swarm. Use `--force` to ignore this message. "
523 523
 						c.mu.Unlock()
524
-						return fmt.Errorf(msg)
524
+						return errors.New(msg)
525 525
 					}
526 526
 					msg += fmt.Sprintf("Removing this node leaves %v managers out of %v. Without a Raft quorum your swarm will be inaccessible. ", reachable-1, reachable+unreachable)
527 527
 				}
... ...
@@ -532,7 +532,7 @@ func (c *Cluster) Leave(force bool) error {
532 532
 
533 533
 		msg += "The only way to restore a swarm that has lost consensus is to reinitialize it with `--force-new-cluster`. Use `--force` to suppress this message."
534 534
 		c.mu.Unlock()
535
-		return fmt.Errorf(msg)
535
+		return errors.New(msg)
536 536
 	}
537 537
 	// release readers in here
538 538
 	if err := nr.Stop(); err != nil {
... ...
@@ -783,12 +783,12 @@ func (c *Cluster) errNoManager(st nodeState) error {
783 783
 		if st.err == errSwarmCertificatesExpired {
784 784
 			return errSwarmCertificatesExpired
785 785
 		}
786
-		return fmt.Errorf("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.")
786
+		return errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.")
787 787
 	}
788 788
 	if st.swarmNode.Manager() != nil {
789
-		return fmt.Errorf("This node is not a swarm manager. Manager is being prepared or has trouble connecting to the cluster.")
789
+		return errors.New("This node is not a swarm manager. Manager is being prepared or has trouble connecting to the cluster.")
790 790
 	}
791
-	return fmt.Errorf("This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.")
791
+	return errors.New("This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager.")
792 792
 }
793 793
 
794 794
 // GetServices returns all services of a managed swarm cluster.
... ...
@@ -849,7 +849,7 @@ func (c *Cluster) imageWithDigestString(ctx context.Context, image string, authC
849 849
 		dockerRef = reference.WithDefaultTag(dockerRef)
850 850
 		namedTaggedRef, ok := dockerRef.(reference.NamedTagged)
851 851
 		if !ok {
852
-			return "", fmt.Errorf("unable to cast image to NamedTagged reference object")
852
+			return "", errors.New("unable to cast image to NamedTagged reference object")
853 853
 		}
854 854
 
855 855
 		repo, _, err := c.config.Backend.GetRepository(ctx, namedTaggedRef, authConfig)
... ...
@@ -896,7 +896,7 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string) (*apity
896 896
 
897 897
 	ctnr := serviceSpec.Task.GetContainer()
898 898
 	if ctnr == nil {
899
-		return nil, fmt.Errorf("service does not use container tasks")
899
+		return nil, errors.New("service does not use container tasks")
900 900
 	}
901 901
 
902 902
 	if encodedAuth != "" {
... ...
@@ -986,7 +986,7 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
986 986
 
987 987
 	newCtnr := serviceSpec.Task.GetContainer()
988 988
 	if newCtnr == nil {
989
-		return nil, fmt.Errorf("service does not use container tasks")
989
+		return nil, errors.New("service does not use container tasks")
990 990
 	}
991 991
 
992 992
 	if encodedAuth != "" {
... ...
@@ -1000,14 +1000,14 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
1000 1000
 			ctnr = currentService.Spec.Task.GetContainer()
1001 1001
 		case apitypes.RegistryAuthFromPreviousSpec:
1002 1002
 			if currentService.PreviousSpec == nil {
1003
-				return nil, fmt.Errorf("service does not have a previous spec")
1003
+				return nil, errors.New("service does not have a previous spec")
1004 1004
 			}
1005 1005
 			ctnr = currentService.PreviousSpec.Task.GetContainer()
1006 1006
 		default:
1007
-			return nil, fmt.Errorf("unsupported registryAuthFromValue")
1007
+			return nil, errors.New("unsupported registryAuthFrom value")
1008 1008
 		}
1009 1009
 		if ctnr == nil {
1010
-			return nil, fmt.Errorf("service does not use container tasks")
1010
+			return nil, errors.New("service does not use container tasks")
1011 1011
 		}
1012 1012
 		newCtnr.PullOptions = ctnr.PullOptions
1013 1013
 		// update encodedAuth so it can be used to pin image by digest
... ...
@@ -1447,7 +1447,7 @@ func (c *Cluster) WaitForDetachment(ctx context.Context, networkName, networkID,
1447 1447
 	state := c.currentNodeState()
1448 1448
 	if state.swarmNode == nil || state.swarmNode.Agent() == nil {
1449 1449
 		c.mu.RUnlock()
1450
-		return fmt.Errorf("invalid cluster node while waiting for detachment")
1450
+		return errors.New("invalid cluster node while waiting for detachment")
1451 1451
 	}
1452 1452
 
1453 1453
 	c.mu.RUnlock()
... ...
@@ -1482,7 +1482,7 @@ func (c *Cluster) AttachNetwork(target string, containerID string, addresses []s
1482 1482
 	state := c.currentNodeState()
1483 1483
 	if state.swarmNode == nil || state.swarmNode.Agent() == nil {
1484 1484
 		c.mu.Unlock()
1485
-		return nil, fmt.Errorf("invalid cluster node while attaching to network")
1485
+		return nil, errors.New("invalid cluster node while attaching to network")
1486 1486
 	}
1487 1487
 	if attacher, ok := c.attachers[aKey]; ok {
1488 1488
 		c.mu.Unlock()
... ...
@@ -1697,7 +1697,7 @@ func validateAndSanitizeJoinRequest(req *types.JoinRequest) error {
1697 1697
 		return fmt.Errorf("invalid ListenAddr %q: %v", req.ListenAddr, err)
1698 1698
 	}
1699 1699
 	if len(req.RemoteAddrs) == 0 {
1700
-		return fmt.Errorf("at least 1 RemoteAddr is required to join")
1700
+		return errors.New("at least 1 RemoteAddr is required to join")
1701 1701
 	}
1702 1702
 	for i := range req.RemoteAddrs {
1703 1703
 		req.RemoteAddrs[i], err = validateAddr(req.RemoteAddrs[i])
... ...
@@ -1710,7 +1710,7 @@ func validateAndSanitizeJoinRequest(req *types.JoinRequest) error {
1710 1710
 
1711 1711
 func validateAddr(addr string) (string, error) {
1712 1712
 	if addr == "" {
1713
-		return addr, fmt.Errorf("invalid empty address")
1713
+		return addr, errors.New("invalid empty address")
1714 1714
 	}
1715 1715
 	newaddr, err := opts.ParseTCPAddr(addr, defaultAddr)
1716 1716
 	if err != nil {
... ...
@@ -1738,7 +1738,7 @@ func initClusterSpec(node *swarmnode.Node, spec types.Spec) error {
1738 1738
 						time.Sleep(200 * time.Millisecond)
1739 1739
 						continue
1740 1740
 					}
1741
-					return fmt.Errorf("empty list of clusters was returned")
1741
+					return errors.New("empty list of clusters was returned")
1742 1742
 				}
1743 1743
 				cluster = lcr.Clusters[0]
1744 1744
 				break
... ...
@@ -3,6 +3,7 @@ package container
3 3
 import (
4 4
 	"encoding/base64"
5 5
 	"encoding/json"
6
+	"errors"
6 7
 	"fmt"
7 8
 	"io"
8 9
 	"strings"
... ...
@@ -238,7 +239,7 @@ func (c *containerAdapter) create(ctx context.Context) error {
238 238
 
239 239
 	container := c.container.task.Spec.GetContainer()
240 240
 	if container == nil {
241
-		return fmt.Errorf("unable to get container from task spec")
241
+		return errors.New("unable to get container from task spec")
242 242
 	}
243 243
 
244 244
 	// configure secrets
... ...
@@ -401,7 +402,7 @@ func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscription
401 401
 		// See protobuf documentation for details of how this works.
402 402
 		apiOptions.Tail = fmt.Sprint(-options.Tail - 1)
403 403
 	} else if options.Tail > 0 {
404
-		return nil, fmt.Errorf("tail relative to start of logs not supported via docker API")
404
+		return nil, errors.New("tail relative to start of logs not supported via docker API")
405 405
 	}
406 406
 
407 407
 	if len(options.Streams) == 0 {
... ...
@@ -1,15 +1,17 @@
1 1
 package container
2 2
 
3
-import "fmt"
3
+import (
4
+	"errors"
5
+)
4 6
 
5 7
 var (
6 8
 	// ErrImageRequired returned if a task is missing the image definition.
7
-	ErrImageRequired = fmt.Errorf("dockerexec: image required")
9
+	ErrImageRequired = errors.New("dockerexec: image required")
8 10
 
9 11
 	// ErrContainerDestroyed returned when a container is prematurely destroyed
10 12
 	// during a wait call.
11
-	ErrContainerDestroyed = fmt.Errorf("dockerexec: container destroyed")
13
+	ErrContainerDestroyed = errors.New("dockerexec: container destroyed")
12 14
 
13 15
 	// ErrContainerUnhealthy returned if controller detects the health check failure
14
-	ErrContainerUnhealthy = fmt.Errorf("dockerexec: unhealthy container")
16
+	ErrContainerUnhealthy = errors.New("dockerexec: unhealthy container")
15 17
 )
... ...
@@ -87,7 +87,7 @@ func TestHealthStates(t *testing.T) {
87 87
 			}
88 88
 		case <-timer.C:
89 89
 			if expectedErr != nil {
90
-				t.Fatalf("time limit exceeded, didn't get expected error")
90
+				t.Fatal("time limit exceeded, didn't get expected error")
91 91
 			}
92 92
 		}
93 93
 	}
... ...
@@ -1,6 +1,7 @@
1 1
 package container
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"os"
6 7
 	"path/filepath"
... ...
@@ -33,7 +34,7 @@ func validateMounts(mounts []api.Mount) error {
33 33
 			}
34 34
 		case api.MountTypeTmpfs:
35 35
 			if mount.Source != "" {
36
-				return fmt.Errorf("invalid tmpfs source, source must be empty")
36
+				return errors.New("invalid tmpfs source, source must be empty")
37 37
 			}
38 38
 		default:
39 39
 			return fmt.Errorf("invalid mount type: %s", mount.Type)
... ...
@@ -229,7 +229,7 @@ func parseClusterAdvertiseSettings(clusterStore, clusterAdvertise string) (strin
229 229
 		return "", errDiscoveryDisabled
230 230
 	}
231 231
 	if clusterStore == "" {
232
-		return "", fmt.Errorf("invalid cluster configuration. --cluster-advertise must be accompanied by --cluster-store configuration")
232
+		return "", errors.New("invalid cluster configuration. --cluster-advertise must be accompanied by --cluster-store configuration")
233 233
 	}
234 234
 
235 235
 	advertise, err := discovery.ParseAdvertise(clusterAdvertise)
... ...
@@ -66,7 +66,7 @@ var (
66 66
 	// DefaultInitBinary is the name of the default init binary
67 67
 	DefaultInitBinary = "docker-init"
68 68
 
69
-	errSystemNotSupported = fmt.Errorf("The Docker daemon is not supported on this platform.")
69
+	errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
70 70
 )
71 71
 
72 72
 // Daemon holds information about the Docker daemon.
... ...
@@ -649,7 +649,7 @@ func NewDaemon(config *Config, registryService registry.Service, containerdRemot
649 649
 	// Check if Devices cgroup is mounted, it is hard requirement for container security,
650 650
 	// on Linux.
651 651
 	if runtime.GOOS == "linux" && !sysInfo.CgroupDevicesEnabled {
652
-		return nil, fmt.Errorf("Devices cgroup isn't mounted")
652
+		return nil, errors.New("Devices cgroup isn't mounted")
653 653
 	}
654 654
 
655 655
 	d.ID = trustKey.PublicKey().KeyID()
... ...
@@ -722,7 +722,7 @@ func (daemon *Daemon) shutdownContainer(c *container.Container) error {
722 722
 		logrus.Debugf("Found container %s is paused, sending SIGTERM before unpausing it", c.ID)
723 723
 		sig, ok := signal.SignalMap["TERM"]
724 724
 		if !ok {
725
-			return fmt.Errorf("System does not support SIGTERM")
725
+			return errors.New("System does not support SIGTERM")
726 726
 		}
727 727
 		if err := daemon.kill(c, int(sig)); err != nil {
728 728
 			return fmt.Errorf("sending SIGTERM to container %s with error: %v", c.ID, err)
... ...
@@ -734,7 +734,7 @@ func (daemon *Daemon) shutdownContainer(c *container.Container) error {
734 734
 			logrus.Debugf("container %s failed to exit in %d second of SIGTERM, sending SIGKILL to force", c.ID, stopTimeout)
735 735
 			sig, ok := signal.SignalMap["KILL"]
736 736
 			if !ok {
737
-				return fmt.Errorf("System does not support SIGKILL")
737
+				return errors.New("System does not support SIGKILL")
738 738
 			}
739 739
 			if err := daemon.kill(c, int(sig)); err != nil {
740 740
 				logrus.Errorf("Failed to SIGKILL container %s", c.ID)
... ...
@@ -954,7 +954,7 @@ func (daemon *Daemon) configureVolumes(rootUID, rootGID int) (*store.VolumeStore
954 954
 	volumedrivers.RegisterPluginGetter(daemon.PluginStore)
955 955
 
956 956
 	if !volumedrivers.Register(volumesDriver, volumesDriver.Name()) {
957
-		return nil, fmt.Errorf("local volume driver could not be registered")
957
+		return nil, errors.New("local volume driver could not be registered")
958 958
 	}
959 959
 	return store.New(daemon.configStore.Root)
960 960
 }
... ...
@@ -1194,7 +1194,7 @@ func (daemon *Daemon) networkOptions(dconfig *Config, pg plugingetter.PluginGett
1194 1194
 	if strings.TrimSpace(dconfig.ClusterStore) != "" {
1195 1195
 		kv := strings.Split(dconfig.ClusterStore, "://")
1196 1196
 		if len(kv) != 2 {
1197
-			return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER://KV-URL")
1197
+			return nil, errors.New("kv store daemon config must be of the form KV-PROVIDER://KV-URL")
1198 1198
 		}
1199 1199
 		options = append(options, nwconfig.OptionKVProvider(kv[0]))
1200 1200
 		options = append(options, nwconfig.OptionKVProviderURL(kv[1]))
... ...
@@ -1,7 +1,7 @@
1 1
 package daemon
2 2
 
3 3
 import (
4
-	"fmt"
4
+	"errors"
5 5
 	"io"
6 6
 	"strconv"
7 7
 	"time"
... ...
@@ -22,7 +22,7 @@ import (
22 22
 // configured with the given struct.
23 23
 func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, config *backend.ContainerLogsConfig, started chan struct{}) error {
24 24
 	if !(config.ShowStdout || config.ShowStderr) {
25
-		return fmt.Errorf("You must choose at least one stream")
25
+		return errors.New("You must choose at least one stream")
26 26
 	}
27 27
 	container, err := daemon.GetContainer(containerName)
28 28
 	if err != nil {
... ...
@@ -1,6 +1,7 @@
1 1
 package daemon
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 	"strings"
6 7
 
... ...
@@ -19,7 +20,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
19 19
 	)
20 20
 
21 21
 	if oldName == "" || newName == "" {
22
-		return fmt.Errorf("Neither old nor new names may be empty")
22
+		return errors.New("Neither old nor new names may be empty")
23 23
 	}
24 24
 
25 25
 	if newName[0] != '/' {
... ...
@@ -35,7 +36,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
35 35
 	oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
36 36
 
37 37
 	if oldName == newName {
38
-		return fmt.Errorf("Renaming a container with the same name as its current name")
38
+		return errors.New("Renaming a container with the same name as its current name")
39 39
 	}
40 40
 
41 41
 	container.Lock()
... ...
@@ -1,7 +1,7 @@
1 1
 package daemon
2 2
 
3 3
 import (
4
-	"fmt"
4
+	"errors"
5 5
 	"strings"
6 6
 	"testing"
7 7
 
... ...
@@ -23,7 +23,7 @@ type FakeService struct {
23 23
 
24 24
 func (s *FakeService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
25 25
 	if s.shouldReturnError {
26
-		return nil, fmt.Errorf("Search unknown error")
26
+		return nil, errors.New("Search unknown error")
27 27
 	}
28 28
 	return &registrytypes.SearchResults{
29 29
 		Query:      s.term,
... ...
@@ -1,6 +1,7 @@
1 1
 package distribution
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"fmt"
5 6
 
6 7
 	"github.com/Sirupsen/logrus"
... ...
@@ -172,7 +173,7 @@ func writeStatus(requestedTag string, out progress.Output, layersDownloaded bool
172 172
 // ValidateRepoName validates the name of a repository.
173 173
 func ValidateRepoName(name string) error {
174 174
 	if name == "" {
175
-		return fmt.Errorf("Repository name can't be empty")
175
+		return errors.New("Repository name can't be empty")
176 176
 	}
177 177
 	if name == api.NoBaseImageSpecifier {
178 178
 		return fmt.Errorf("'%s' is a reserved name", api.NoBaseImageSpecifier)