diff --git a/api/server/middleware/version.go b/api/server/middleware/version.go index c8f9c7340b..ef35c728f1 100644 --- a/api/server/middleware/version.go +++ b/api/server/middleware/version.go @@ -53,6 +53,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http. w.Header().Set("Server", header) w.Header().Set("API-Version", v.defaultVersion) w.Header().Set("OSType", runtime.GOOS) + // nolint: golint ctx = context.WithValue(ctx, "api-version", apiVersion) return handler(ctx, w, r, vars) } diff --git a/builder/dockerfile/parser/line_parsers.go b/builder/dockerfile/parser/line_parsers.go index d0e182e8e3..2c375b74e4 100644 --- a/builder/dockerfile/parser/line_parsers.go +++ b/builder/dockerfile/parser/line_parsers.go @@ -19,7 +19,7 @@ import ( ) var ( - errDockerfileNotStringArray = errors.New("When using JSON array syntax, arrays must be comprised of strings only.") + errDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only") ) const ( diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index d36c294ec3..0a3a0be388 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -453,7 +453,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) { c, err := config.MergeDaemonConfigurations(conf, flags, opts.configFile) if err != nil { if flags.Changed("config-file") || !os.IsNotExist(err) { - return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v\n", opts.configFile, err) + return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v", opts.configFile, err) } } // the merged configuration can be nil if the config file didn't exist. diff --git a/daemon/attach.go b/daemon/attach.go index ef1765af92..7b676ccaf0 100644 --- a/daemon/attach.go +++ b/daemon/attach.go @@ -31,11 +31,11 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA return err } if container.IsPaused() { - err := fmt.Errorf("Container %s is paused, unpause the container before attach.", prefixOrName) + err := fmt.Errorf("container %s is paused, unpause the container before attach", prefixOrName) return stateConflictError{err} } if container.IsRestarting() { - err := fmt.Errorf("Container %s is restarting, wait until the container is running.", prefixOrName) + err := fmt.Errorf("container %s is restarting, wait until the container is running", prefixOrName) return stateConflictError{err} } diff --git a/daemon/daemon.go b/daemon/daemon.go index ebfdb68d1d..7322eea990 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -66,7 +66,7 @@ var ( // containerd if none is specified DefaultRuntimeBinary = "docker-runc" - errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.") + errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform") ) type daemonStore struct { diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 1ebebf6628..b0aec72a4c 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -557,13 +557,13 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes. // check for various conflicting options with user namespaces if daemon.configStore.RemappedRoot != "" && hostConfig.UsernsMode.IsPrivate() { if hostConfig.Privileged { - return warnings, fmt.Errorf("Privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode.") + return warnings, fmt.Errorf("privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode") } if hostConfig.NetworkMode.IsHost() && !hostConfig.UsernsMode.IsHost() { - return warnings, fmt.Errorf("Cannot share the host's network namespace when user namespaces are enabled") + return warnings, fmt.Errorf("cannot share the host's network namespace when user namespaces are enabled") } if hostConfig.PidMode.IsHost() && !hostConfig.UsernsMode.IsHost() { - return warnings, fmt.Errorf("Cannot share the host PID namespace when user namespaces are enabled") + return warnings, fmt.Errorf("cannot share the host PID namespace when user namespaces are enabled") } } if hostConfig.CgroupParent != "" && UsingSystemd(daemon.configStore) { @@ -1125,7 +1125,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, rootIDs idtools.IDPa break } if !idtools.CanAccess(dirPath, rootIDs) { - return fmt.Errorf("A subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories.", config.Root) + return fmt.Errorf("a subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories", config.Root) } } } diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go index 95d9df7cb0..32b35c9acd 100644 --- a/daemon/graphdriver/devmapper/deviceset.go +++ b/daemon/graphdriver/devmapper/deviceset.go @@ -2664,7 +2664,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [ devices.metaDataLoopbackSize = size case "dm.fs": if val != "ext4" && val != "xfs" { - return nil, fmt.Errorf("devmapper: Unsupported filesystem %s\n", val) + return nil, fmt.Errorf("devmapper: Unsupported filesystem %s", val) } devices.filesystem = val case "dm.mkfsarg": @@ -2786,7 +2786,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [ Level: int(level), }) default: - return nil, fmt.Errorf("devmapper: Unknown option %s\n", key) + return nil, fmt.Errorf("devmapper: Unknown option %s", key) } } diff --git a/daemon/graphdriver/overlay/copy.go b/daemon/graphdriver/overlay/copy.go index 53ea5bff11..b8c3176941 100644 --- a/daemon/graphdriver/overlay/copy.go +++ b/daemon/graphdriver/overlay/copy.go @@ -121,7 +121,7 @@ func copyDir(srcDir, dstDir string, flags copyFlags) error { } default: - return fmt.Errorf("Unknown file type for %s\n", srcPath) + return fmt.Errorf("unknown file type for %s", srcPath) } // Everything below is copying metadata from src to dst. All this metadata diff --git a/daemon/health.go b/daemon/health.go index c8e84a2d1f..e10fe87104 100644 --- a/daemon/health.go +++ b/daemon/health.go @@ -101,7 +101,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container return nil, err } if info.ExitCode == nil { - return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", cntr.ID) + return nil, fmt.Errorf("healthcheck for container %s has no exit code", cntr.ID) } // Note: Go's json package will handle invalid UTF-8 for us out := output.String() diff --git a/daemon/logger/awslogs/cloudwatchlogs_test.go b/daemon/logger/awslogs/cloudwatchlogs_test.go index 8688026a0d..989eb6f52c 100644 --- a/daemon/logger/awslogs/cloudwatchlogs_test.go +++ b/daemon/logger/awslogs/cloudwatchlogs_test.go @@ -162,7 +162,7 @@ func TestCreateError(t *testing.T) { client: mockClient, } mockClient.createLogStreamResult <- &createLogStreamResult{ - errorResult: errors.New("Error!"), + errorResult: errors.New("Error"), } err := stream.create() @@ -243,7 +243,7 @@ func TestPublishBatchError(t *testing.T) { sequenceToken: aws.String(sequenceToken), } mockClient.putLogEventsResult <- &putLogEventsResult{ - errorResult: errors.New("Error!"), + errorResult: errors.New("Error"), } events := []wrappedEvent{ diff --git a/daemon/logger/splunk/splunk.go b/daemon/logger/splunk/splunk.go index 7319a3e3d5..274904bec1 100644 --- a/daemon/logger/splunk/splunk.go +++ b/daemon/logger/splunk/splunk.go @@ -203,7 +203,7 @@ func New(info logger.Info) (logger.Logger, error) { } gzipCompressionLevel = int(gzipCompressionLevel64) if gzipCompressionLevel < gzip.DefaultCompression || gzipCompressionLevel > gzip.BestCompression { - err := fmt.Errorf("Not supported level '%s' for %s (supported values between %d and %d).", + err := fmt.Errorf("not supported level '%s' for %s (supported values between %d and %d)", gzipCompressionLevelStr, splunkGzipCompressionLevelKey, gzip.DefaultCompression, gzip.BestCompression) return nil, err } diff --git a/daemon/monitor.go b/daemon/monitor.go index 3fd7bffb87..3946e7aaec 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -36,7 +36,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error { case libcontainerd.StateOOM: // StateOOM is Linux specific and should never be hit on Windows if runtime.GOOS == "windows" { - return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.") + return errors.New("received StateOOM from libcontainerd on Windows. This should never happen") } daemon.updateHealthMonitor(c) if err := c.CheckpointTo(daemon.containersReplica); err != nil { diff --git a/daemon/network.go b/daemon/network.go index 2d27e108d2..62fe951cbb 100644 --- a/daemon/network.go +++ b/daemon/network.go @@ -348,6 +348,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string n, err := c.NewNetwork(driver, create.Name, id, nwOptions...) if err != nil { if _, ok := err.(libnetwork.ErrDataStoreNotInitialized); ok { + // nolint: golint return nil, 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.") } return nil, err diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 53b246a2d2..283b7dd367 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -438,7 +438,7 @@ func ensureShared(path string) error { } if !sharedMount { - return fmt.Errorf("Path %s is mounted on %s but it is not a shared mount.", path, sourceMount) + return fmt.Errorf("path %s is mounted on %s but it is not a shared mount", path, sourceMount) } return nil } @@ -465,7 +465,7 @@ func ensureSharedOrSlave(path string) error { } if !sharedMount && !slaveMount { - return fmt.Errorf("Path %s is mounted on %s but it is not a shared or slave mount.", path, sourceMount) + return fmt.Errorf("path %s is mounted on %s but it is not a shared or slave mount", path, sourceMount) } return nil } diff --git a/daemon/start.go b/daemon/start.go index 901f270798..55438cf2c4 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -27,7 +27,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos defer container.Unlock() if container.Paused { - return stateConflictError{errors.New("Cannot start a paused container, try unpause instead.")} + return stateConflictError{errors.New("cannot start a paused container, try unpause instead")} } if container.Running { @@ -35,7 +35,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos } if container.RemovalInProgress || container.Dead { - return stateConflictError{errors.New("Container is marked for removal and cannot be started.")} + return stateConflictError{errors.New("container is marked for removal and cannot be started")} } return nil } @@ -110,7 +110,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint } if container.RemovalInProgress || container.Dead { - return stateConflictError{errors.New("Container is marked for removal and cannot be started.")} + return stateConflictError{errors.New("container is marked for removal and cannot be started")} } // if we encounter an error during start we need to ensure that any other diff --git a/daemon/update.go b/daemon/update.go index ee39e05cb0..42d732f262 100644 --- a/daemon/update.go +++ b/daemon/update.go @@ -50,7 +50,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro }() if container.RemovalInProgress || container.Dead { - return errCannotUpdate(container.ID, fmt.Errorf("Container is marked for removal and cannot be \"update\".")) + return errCannotUpdate(container.ID, fmt.Errorf("container is marked for removal and cannot be \"update\"")) } container.Lock() diff --git a/distribution/pull_v2.go b/distribution/pull_v2.go index 9bc704d12d..55c83f58cc 100644 --- a/distribution/pull_v2.go +++ b/distribution/pull_v2.go @@ -908,7 +908,7 @@ func fixManifestLayers(m *schema1.Manifest) error { m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...) m.History = append(m.History[:i], m.History[i+1:]...) } else if imgs[i].Parent != imgs[i+1].ID { - return fmt.Errorf("Invalid parent ID. Expected %v, got %v.", imgs[i+1].ID, imgs[i].Parent) + return fmt.Errorf("invalid parent ID. Expected %v, got %v", imgs[i+1].ID, imgs[i].Parent) } } diff --git a/distribution/pull_v2_test.go b/distribution/pull_v2_test.go index df93c1ef83..698670f891 100644 --- a/distribution/pull_v2_test.go +++ b/distribution/pull_v2_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/reference" + "github.com/docker/docker/pkg/testutil" "github.com/opencontainers/go-digest" ) @@ -102,9 +103,8 @@ func TestFixManifestLayersBadParent(t *testing.T) { }, } - if err := fixManifestLayers(&duplicateLayerManifest); err == nil || !strings.Contains(err.Error(), "Invalid parent ID.") { - t.Fatalf("expected an invalid parent ID error from fixManifestLayers") - } + err := fixManifestLayers(&duplicateLayerManifest) + testutil.ErrorContains(t, err, "invalid parent ID") } // TestValidateManifest verifies the validateManifest function diff --git a/hack/validate/gometalinter.json b/hack/validate/gometalinter.json index 867bac7429..4b6049065f 100644 --- a/hack/validate/gometalinter.json +++ b/hack/validate/gometalinter.json @@ -2,7 +2,12 @@ "Vendor": true, "Deadline": "2m", "Sort": ["linter", "severity", "path"], - "Exclude": [".*\\.pb\\.go"], + "Exclude": [ + ".*\\.pb\\.go", + "dockerversion/version_autogen.go", + "api/types/container/container_.*", + "integration-cli/" + ], "Enable": [ "gofmt", diff --git a/integration-cli/docker_cli_start_test.go b/integration-cli/docker_cli_start_test.go index 2dd5fdf5fc..9f54522690 100644 --- a/integration-cli/docker_cli_start_test.go +++ b/integration-cli/docker_cli_start_test.go @@ -103,7 +103,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) { // an error should have been shown that you cannot start paused container c.Assert(err, checker.NotNil, check.Commentf("out: %s", out)) // an error should have been shown that you cannot start paused container - c.Assert(out, checker.Contains, "Cannot start a paused container, try unpause instead.") + c.Assert(out, checker.Contains, "cannot start a paused container, try unpause instead") } func (s *DockerSuite) TestStartMultipleContainers(c *check.C) { diff --git a/pkg/archive/archive.go b/pkg/archive/archive.go index b3c84ee156..c3bcbc6552 100644 --- a/pkg/archive/archive.go +++ b/pkg/archive/archive.go @@ -595,7 +595,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L return nil default: - return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag) + return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag) } // Lchown is not supported on Windows. diff --git a/pkg/ioutils/readers_test.go b/pkg/ioutils/readers_test.go index 9abc1054df..86e50d38f9 100644 --- a/pkg/ioutils/readers_test.go +++ b/pkg/ioutils/readers_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -14,7 +15,7 @@ import ( type errorReader struct{} func (r *errorReader) Read(p []byte) (int, error) { - return 0, fmt.Errorf("Error reader always fail.") + return 0, fmt.Errorf("error reader always fail") } func TestReadCloserWrapperClose(t *testing.T) { @@ -35,9 +36,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) { called = true }) _, err := wrapper.Read([]byte{}) - if err == nil || !strings.Contains(err.Error(), "Error reader always fail.") { - t.Fatalf("readErrWrapper should returned an error") - } + assert.EqualError(t, err, "error reader always fail") if !called { t.Fatalf("readErrWrapper should have call the anonymous function on failure") } diff --git a/pkg/jsonmessage/jsonmessage.go b/pkg/jsonmessage/jsonmessage.go index dc785d6187..09fc4cc745 100644 --- a/pkg/jsonmessage/jsonmessage.go +++ b/pkg/jsonmessage/jsonmessage.go @@ -8,11 +8,10 @@ import ( "strings" "time" - "github.com/Nvveen/Gotty" - + gotty "github.com/Nvveen/Gotty" "github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/term" - "github.com/docker/go-units" + units "github.com/docker/go-units" ) // JSONError wraps a concrete Code and Message, `Code` is @@ -187,7 +186,7 @@ func cursorDown(out io.Writer, ti termInfo, l int) { func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error { if jm.Error != nil { if jm.Error.Code == 401 { - return fmt.Errorf("Authentication is required.") + return fmt.Errorf("authentication is required") } return jm.Error } diff --git a/pkg/jsonmessage/jsonmessage_test.go b/pkg/jsonmessage/jsonmessage_test.go index c3ed6c046a..5206789ac2 100644 --- a/pkg/jsonmessage/jsonmessage_test.go +++ b/pkg/jsonmessage/jsonmessage_test.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/term" + "github.com/stretchr/testify/assert" ) func TestError(t *testing.T) { @@ -198,9 +199,7 @@ func TestJSONMessageDisplayWithJSONError(t *testing.T) { jsonMessage = JSONMessage{Error: &JSONError{401, "Anything"}} err = jsonMessage.Display(data, &noTermInfo{}) - if err == nil || err.Error() != "Authentication is required." { - t.Fatalf("Expected an error \"Authentication is required.\", got %q", err) - } + assert.EqualError(t, err, "authentication is required") } func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) { diff --git a/pkg/testutil/cmd/command.go b/pkg/testutil/cmd/command.go index 6f36d67908..05ca55e47e 100644 --- a/pkg/testutil/cmd/command.go +++ b/pkg/testutil/cmd/command.go @@ -61,7 +61,7 @@ func (r *Result) Assert(t testingT, exp Expected) *Result { } _, file, line, ok := runtime.Caller(1) if ok { - t.Fatalf("at %s:%d - %s", filepath.Base(file), line, err.Error()) + t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error()) } else { t.Fatalf("(no file/line info) - %s", err.Error()) } @@ -108,7 +108,7 @@ func (r *Result) Compare(exp Expected) error { if len(errors) == 0 { return nil } - return fmt.Errorf("%s\nFailures:\n%s\n", r, strings.Join(errors, "\n")) + return fmt.Errorf("%s\nFailures:\n%s", r, strings.Join(errors, "\n")) } func matchOutput(expected string, actual string) bool { diff --git a/registry/auth.go b/registry/auth.go index 493626bcdc..9222dfffbc 100644 --- a/registry/auth.go +++ b/registry/auth.go @@ -29,7 +29,7 @@ func loginV1(authConfig *types.AuthConfig, apiEndpoint APIEndpoint, userAgent st logrus.Debugf("attempting v1 login to registry endpoint %s", serverAddress) if serverAddress == "" { - return "", "", systemError{errors.New("Server Error: Server Address not set.")} + return "", "", systemError{errors.New("server Error: Server Address not set")} } req, err := http.NewRequest("GET", serverAddress+"users/", nil) diff --git a/registry/config.go b/registry/config.go index f4b3bff945..f3eb537b52 100644 --- a/registry/config.go +++ b/registry/config.go @@ -354,7 +354,7 @@ func ValidateIndexName(val string) (string, error) { val = "docker.io" } if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") { - return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val) + return "", fmt.Errorf("invalid index name (%s). Cannot begin or end with a hyphen", val) } return val, nil } diff --git a/registry/registry.go b/registry/registry.go index a676d63450..5fef0dbccb 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -81,7 +81,7 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error { keyName := certName[:len(certName)-5] + ".key" logrus.Debugf("cert: %s", filepath.Join(directory, f.Name())) if !hasFile(fs, keyName) { - return fmt.Errorf("Missing key %s for client certificate %s. Note that CA certificates should use the extension .crt.", keyName, certName) + return fmt.Errorf("missing key %s for client certificate %s. Note that CA certificates should use the extension .crt", keyName, certName) } cert, err := tls.LoadX509KeyPair(filepath.Join(directory, certName), filepath.Join(directory, keyName)) if err != nil { diff --git a/registry/session.go b/registry/session.go index eaa5aec750..e619d9f644 100644 --- a/registry/session.go +++ b/registry/session.go @@ -434,7 +434,7 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro // "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout" // was a top search on the docker user forum if isTimeout(err) { - return nil, fmt.Errorf("Network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy.", repositoryTarget) + return nil, fmt.Errorf("network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy", repositoryTarget) } return nil, fmt.Errorf("Error while pulling image: %v", err) }