github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/errors.go (about) 1 package daemon // import "github.com/docker/docker/daemon" 2 3 import ( 4 "fmt" 5 "strings" 6 "syscall" 7 8 "github.com/docker/docker/errdefs" 9 "github.com/pkg/errors" 10 "google.golang.org/grpc/status" 11 ) 12 13 func errNotRunning(id string) error { 14 return errdefs.Conflict(errors.Errorf("Container %s is not running", id)) 15 } 16 17 func containerNotFound(id string) error { 18 return objNotFoundError{"container", id} 19 } 20 21 type objNotFoundError struct { 22 object string 23 id string 24 } 25 26 func (e objNotFoundError) Error() string { 27 return "No such " + e.object + ": " + e.id 28 } 29 30 func (e objNotFoundError) NotFound() {} 31 32 func errContainerIsRestarting(containerID string) error { 33 cause := errors.Errorf("Container %s is restarting, wait until the container is running", containerID) 34 return errdefs.Conflict(cause) 35 } 36 37 func errExecNotFound(id string) error { 38 return objNotFoundError{"exec instance", id} 39 } 40 41 func errExecPaused(id string) error { 42 cause := errors.Errorf("Container %s is paused, unpause the container before exec", id) 43 return errdefs.Conflict(cause) 44 } 45 46 func errNotPaused(id string) error { 47 cause := errors.Errorf("Container %s is already paused", id) 48 return errdefs.Conflict(cause) 49 } 50 51 type nameConflictError struct { 52 id string 53 name string 54 } 55 56 func (e nameConflictError) Error() string { 57 return fmt.Sprintf("Conflict. The container name %q is already in use by container %q. You have to remove (or rename) that container to be able to reuse that name.", e.name, e.id) 58 } 59 60 func (nameConflictError) Conflict() {} 61 62 type containerNotModifiedError struct { 63 running bool 64 } 65 66 func (e containerNotModifiedError) Error() string { 67 if e.running { 68 return "Container is already started" 69 } 70 return "Container is already stopped" 71 } 72 73 func (e containerNotModifiedError) NotModified() {} 74 75 type invalidIdentifier string 76 77 func (e invalidIdentifier) Error() string { 78 return fmt.Sprintf("invalid name or ID supplied: %q", string(e)) 79 } 80 81 func (invalidIdentifier) InvalidParameter() {} 82 83 type incompatibleDeviceRequest struct { 84 driver string 85 caps [][]string 86 } 87 88 func (i incompatibleDeviceRequest) Error() string { 89 return fmt.Sprintf("could not select device driver %q with capabilities: %v", i.driver, i.caps) 90 } 91 92 func (incompatibleDeviceRequest) InvalidParameter() {} 93 94 type duplicateMountPointError string 95 96 func (e duplicateMountPointError) Error() string { 97 return "Duplicate mount point: " + string(e) 98 } 99 func (duplicateMountPointError) InvalidParameter() {} 100 101 type containerFileNotFound struct { 102 file string 103 container string 104 } 105 106 func (e containerFileNotFound) Error() string { 107 return "Could not find the file " + e.file + " in container " + e.container 108 } 109 110 func (containerFileNotFound) NotFound() {} 111 112 type invalidFilter struct { 113 filter string 114 value interface{} 115 } 116 117 func (e invalidFilter) Error() string { 118 msg := "Invalid filter '" + e.filter 119 if e.value != nil { 120 msg += fmt.Sprintf("=%s", e.value) 121 } 122 return msg + "'" 123 } 124 125 func (e invalidFilter) InvalidParameter() {} 126 127 type startInvalidConfigError string 128 129 func (e startInvalidConfigError) Error() string { 130 return string(e) 131 } 132 133 func (e startInvalidConfigError) InvalidParameter() {} // Is this right??? 134 135 func translateContainerdStartErr(cmd string, setExitCode func(int), err error) error { 136 errDesc := status.Convert(err).Message() 137 contains := func(s1, s2 string) bool { 138 return strings.Contains(strings.ToLower(s1), s2) 139 } 140 var retErr = errdefs.Unknown(errors.New(errDesc)) 141 // if we receive an internal error from the initial start of a container then lets 142 // return it instead of entering the restart loop 143 // set to 127 for container cmd not found/does not exist) 144 if contains(errDesc, cmd) && 145 (contains(errDesc, "executable file not found") || 146 contains(errDesc, "no such file or directory") || 147 contains(errDesc, "system cannot find the file specified") || 148 contains(errDesc, "failed to run runc create/exec call")) { 149 setExitCode(127) 150 retErr = startInvalidConfigError(errDesc) 151 } 152 // set to 126 for container cmd can't be invoked errors 153 if contains(errDesc, syscall.EACCES.Error()) { 154 setExitCode(126) 155 retErr = startInvalidConfigError(errDesc) 156 } 157 158 // attempted to mount a file onto a directory, or a directory onto a file, maybe from user specified bind mounts 159 if contains(errDesc, syscall.ENOTDIR.Error()) { 160 errDesc += ": Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type" 161 setExitCode(127) 162 retErr = startInvalidConfigError(errDesc) 163 } 164 165 // TODO: it would be nice to get some better errors from containerd so we can return better errors here 166 return retErr 167 }