Signed-off-by: Doug Davis <dug@us.ibm.com>
| ... | ... |
@@ -18,4 +18,475 @@ var ( |
| 18 | 18 |
Description: "The specified container can not be found", |
| 19 | 19 |
HTTPStatusCode: http.StatusNotFound, |
| 20 | 20 |
}) |
| 21 |
+ |
|
| 22 |
+ // ErrorCodeUnregisteredContainer is generated when we try to load |
|
| 23 |
+ // a storage driver for an unregistered container |
|
| 24 |
+ ErrorCodeUnregisteredContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 25 |
+ Value: "UNREGISTEREDCONTAINER", |
|
| 26 |
+ Message: "Can't load storage driver for unregistered container %s", |
|
| 27 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 28 |
+ }) |
|
| 29 |
+ |
|
| 30 |
+ // ErrorCodeContainerBeingRemoved is generated when an attempt to start |
|
| 31 |
+ // a container is made but its in the process of being removed, or is dead. |
|
| 32 |
+ ErrorCodeContainerBeingRemoved = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 33 |
+ Value: "CONTAINERBEINGREMOVED", |
|
| 34 |
+ Message: "Container is marked for removal and cannot be started.", |
|
| 35 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 36 |
+ }) |
|
| 37 |
+ |
|
| 38 |
+ // ErrorCodeUnpauseContainer is generated when we attempt to stop a |
|
| 39 |
+ // container but its paused. |
|
| 40 |
+ ErrorCodeUnpauseContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 41 |
+ Value: "UNPAUSECONTAINER", |
|
| 42 |
+ Message: "Container %s is paused. Unpause the container before stopping", |
|
| 43 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 44 |
+ }) |
|
| 45 |
+ |
|
| 46 |
+ // ErrorCodeAlreadyPaused is generated when we attempt to pause a |
|
| 47 |
+ // container when its already paused. |
|
| 48 |
+ ErrorCodeAlreadyPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 49 |
+ Value: "ALREADYPAUSED", |
|
| 50 |
+ Message: "Container %s is already paused", |
|
| 51 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 52 |
+ }) |
|
| 53 |
+ |
|
| 54 |
+ // ErrorCodeNotPaused is generated when we attempt to unpause a |
|
| 55 |
+ // container when its not paused. |
|
| 56 |
+ ErrorCodeNotPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 57 |
+ Value: "NOTPAUSED", |
|
| 58 |
+ Message: "Container %s is not paused", |
|
| 59 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 60 |
+ }) |
|
| 61 |
+ |
|
| 62 |
+ // ErrorCodeImageUnregContainer is generated when we attempt to get the |
|
| 63 |
+ // image of an unknown/unregistered container. |
|
| 64 |
+ ErrorCodeImageUnregContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 65 |
+ Value: "IMAGEUNREGCONTAINER", |
|
| 66 |
+ Message: "Can't get image of unregistered container", |
|
| 67 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 68 |
+ }) |
|
| 69 |
+ |
|
| 70 |
+ // ErrorCodeEmptyID is generated when an ID is the emptry string. |
|
| 71 |
+ ErrorCodeEmptyID = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 72 |
+ Value: "EMPTYID", |
|
| 73 |
+ Message: "Invalid empty id", |
|
| 74 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 75 |
+ }) |
|
| 76 |
+ |
|
| 77 |
+ // ErrorCodeLoggingFactory is generated when we could not load the |
|
| 78 |
+ // log driver. |
|
| 79 |
+ ErrorCodeLoggingFactory = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 80 |
+ Value: "LOGGINGFACTORY", |
|
| 81 |
+ Message: "Failed to get logging factory: %v", |
|
| 82 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 83 |
+ }) |
|
| 84 |
+ |
|
| 85 |
+ // ErrorCodeInitLogger is generated when we could not initialize |
|
| 86 |
+ // the logging driver. |
|
| 87 |
+ ErrorCodeInitLogger = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 88 |
+ Value: "INITLOGGER", |
|
| 89 |
+ Message: "Failed to initialize logging driver: %v", |
|
| 90 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 91 |
+ }) |
|
| 92 |
+ |
|
| 93 |
+ // ErrorCodeNotRunning is generated when we need to verify that |
|
| 94 |
+ // a container is running, but its not. |
|
| 95 |
+ ErrorCodeNotRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 96 |
+ Value: "NOTRUNNING", |
|
| 97 |
+ Message: "Container %s is not running", |
|
| 98 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 99 |
+ }) |
|
| 100 |
+ |
|
| 101 |
+ // ErrorCodeLinkNotRunning is generated when we try to link to a |
|
| 102 |
+ // container that is not running. |
|
| 103 |
+ ErrorCodeLinkNotRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 104 |
+ Value: "LINKNOTRUNNING", |
|
| 105 |
+ Message: "Cannot link to a non running container: %s AS %s", |
|
| 106 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 107 |
+ }) |
|
| 108 |
+ |
|
| 109 |
+ // ErrorCodeDeviceInfo is generated when there is an error while trying |
|
| 110 |
+ // to get info about a custom device. |
|
| 111 |
+ // container that is not running. |
|
| 112 |
+ ErrorCodeDeviceInfo = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 113 |
+ Value: "DEVICEINFO", |
|
| 114 |
+ Message: "error gathering device information while adding custom device %q: %s", |
|
| 115 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 116 |
+ }) |
|
| 117 |
+ |
|
| 118 |
+ // ErrorCodeEmptyEndpoint is generated when the endpoint for a port |
|
| 119 |
+ // map is nil. |
|
| 120 |
+ ErrorCodeEmptyEndpoint = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 121 |
+ Value: "EMPTYENDPOINT", |
|
| 122 |
+ Message: "invalid endpoint while building port map info", |
|
| 123 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 124 |
+ }) |
|
| 125 |
+ |
|
| 126 |
+ // ErrorCodeEmptyNetwork is generated when the networkSettings for a port |
|
| 127 |
+ // map is nil. |
|
| 128 |
+ ErrorCodeEmptyNetwork = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 129 |
+ Value: "EMPTYNETWORK", |
|
| 130 |
+ Message: "invalid networksettings while building port map info", |
|
| 131 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 132 |
+ }) |
|
| 133 |
+ |
|
| 134 |
+ // ErrorCodeParsingPort is generated when there is an error parsing |
|
| 135 |
+ // a "port" string. |
|
| 136 |
+ ErrorCodeParsingPort = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 137 |
+ Value: "PARSINGPORT", |
|
| 138 |
+ Message: "Error parsing Port value(%v):%v", |
|
| 139 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 140 |
+ }) |
|
| 141 |
+ |
|
| 142 |
+ // ErrorCodeNoSandbox is generated when we can't find the specified |
|
| 143 |
+ // sandbox(network) by ID. |
|
| 144 |
+ ErrorCodeNoSandbox = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 145 |
+ Value: "NOSANDBOX", |
|
| 146 |
+ Message: "error locating sandbox id %s: %v", |
|
| 147 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 148 |
+ }) |
|
| 149 |
+ |
|
| 150 |
+ // ErrorCodeNetworkUpdate is generated when there is an error while |
|
| 151 |
+ // trying update a network/sandbox config. |
|
| 152 |
+ ErrorCodeNetworkUpdate = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 153 |
+ Value: "NETWORKUPDATE", |
|
| 154 |
+ Message: "Update network failed: %v", |
|
| 155 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 156 |
+ }) |
|
| 157 |
+ |
|
| 158 |
+ // ErrorCodeNetworkRefresh is generated when there is an error while |
|
| 159 |
+ // trying refresh a network/sandbox config. |
|
| 160 |
+ ErrorCodeNetworkRefresh = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 161 |
+ Value: "NETWORKREFRESH", |
|
| 162 |
+ Message: "Update network failed: Failure in refresh sandbox %s: %v", |
|
| 163 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 164 |
+ }) |
|
| 165 |
+ |
|
| 166 |
+ // ErrorCodeHostPort is generated when there was an error while trying |
|
| 167 |
+ // to parse a "host/por" string. |
|
| 168 |
+ ErrorCodeHostPort = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 169 |
+ Value: "HOSTPORT", |
|
| 170 |
+ Message: "Error parsing HostPort value(%s):%v", |
|
| 171 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 172 |
+ }) |
|
| 173 |
+ |
|
| 174 |
+ // ErrorCodeNetworkConflict is generated when we try to public a service |
|
| 175 |
+ // in network mode. |
|
| 176 |
+ ErrorCodeNetworkConflict = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 177 |
+ Value: "NETWORKCONFLICT", |
|
| 178 |
+ Message: "conflicting options: publishing a service and network mode", |
|
| 179 |
+ HTTPStatusCode: http.StatusConflict, |
|
| 180 |
+ }) |
|
| 181 |
+ |
|
| 182 |
+ // ErrorCodeJoinInfo is generated when we failed to update a container's |
|
| 183 |
+ // join info. |
|
| 184 |
+ ErrorCodeJoinInfo = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 185 |
+ Value: "JOININFO", |
|
| 186 |
+ Message: "Updating join info failed: %v", |
|
| 187 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 188 |
+ }) |
|
| 189 |
+ |
|
| 190 |
+ // ErrorCodeIPCRunning is generated when we try to join a container's |
|
| 191 |
+ // IPC but its running. |
|
| 192 |
+ ErrorCodeIPCRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 193 |
+ Value: "IPCRUNNING", |
|
| 194 |
+ Message: "cannot join IPC of a non running container: %s", |
|
| 195 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 196 |
+ }) |
|
| 197 |
+ |
|
| 198 |
+ // ErrorCodeNotADir is generated when we try to create a directory |
|
| 199 |
+ // but the path isn't a dir. |
|
| 200 |
+ ErrorCodeNotADir = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 201 |
+ Value: "NOTADIR", |
|
| 202 |
+ Message: "Cannot mkdir: %s is not a directory", |
|
| 203 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 204 |
+ }) |
|
| 205 |
+ |
|
| 206 |
+ // ErrorCodeParseContainer is generated when the reference to a |
|
| 207 |
+ // container doesn't include a ":" (another container). |
|
| 208 |
+ ErrorCodeParseContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 209 |
+ Value: "PARSECONTAINER", |
|
| 210 |
+ Message: "no container specified to join network", |
|
| 211 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 212 |
+ }) |
|
| 213 |
+ |
|
| 214 |
+ // ErrorCodeJoinSelf is generated when we try to network to ourselves. |
|
| 215 |
+ ErrorCodeJoinSelf = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 216 |
+ Value: "JOINSELF", |
|
| 217 |
+ Message: "cannot join own network", |
|
| 218 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 219 |
+ }) |
|
| 220 |
+ |
|
| 221 |
+ // ErrorCodeJoinRunning is generated when we try to network to ourselves. |
|
| 222 |
+ ErrorCodeJoinRunning = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 223 |
+ Value: "JOINRUNNING", |
|
| 224 |
+ Message: "cannot join network of a non running container: %s", |
|
| 225 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 226 |
+ }) |
|
| 227 |
+ |
|
| 228 |
+ // ErrorCodeModeNotContainer is generated when we try to network to |
|
| 229 |
+ // another container but the mode isn't 'container'. |
|
| 230 |
+ ErrorCodeModeNotContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 231 |
+ Value: "MODENOTCONTAINER", |
|
| 232 |
+ Message: "network mode not set to container", |
|
| 233 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 234 |
+ }) |
|
| 235 |
+ |
|
| 236 |
+ // ErrorCodeRemovingVolume is generated when we try remove a mount |
|
| 237 |
+ // point (volume) but fail. |
|
| 238 |
+ ErrorCodeRemovingVolume = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 239 |
+ Value: "REMOVINGVOLUME", |
|
| 240 |
+ Message: "Error removing volumes:\n%v", |
|
| 241 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 242 |
+ }) |
|
| 243 |
+ |
|
| 244 |
+ // ErrorCodeInvalidNetworkMode is generated when an invalid network |
|
| 245 |
+ // mode value is specified. |
|
| 246 |
+ ErrorCodeInvalidNetworkMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 247 |
+ Value: "INVALIDNETWORKMODE", |
|
| 248 |
+ Message: "invalid network mode: %s", |
|
| 249 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 250 |
+ }) |
|
| 251 |
+ |
|
| 252 |
+ // ErrorCodeGetGraph is generated when there was an error while |
|
| 253 |
+ // trying to find a graph/image. |
|
| 254 |
+ ErrorCodeGetGraph = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 255 |
+ Value: "GETGRAPH", |
|
| 256 |
+ Message: "Failed to graph.Get on ImageID %s - %s", |
|
| 257 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 258 |
+ }) |
|
| 259 |
+ |
|
| 260 |
+ // ErrorCodeGetLayer is generated when there was an error while |
|
| 261 |
+ // trying to retrieve a particular layer of an image. |
|
| 262 |
+ ErrorCodeGetLayer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 263 |
+ Value: "GETLAYER", |
|
| 264 |
+ Message: "Failed to get layer path from graphdriver %s for ImageID %s - %s", |
|
| 265 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 266 |
+ }) |
|
| 267 |
+ |
|
| 268 |
+ // ErrorCodePutLayer is generated when there was an error while |
|
| 269 |
+ // trying to 'put' a particular layer of an image. |
|
| 270 |
+ ErrorCodePutLayer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 271 |
+ Value: "PUTLAYER", |
|
| 272 |
+ Message: "Failed to put layer path from graphdriver %s for ImageID %s - %s", |
|
| 273 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 274 |
+ }) |
|
| 275 |
+ |
|
| 276 |
+ // ErrorCodeGetLayerMetadata is generated when there was an error while |
|
| 277 |
+ // trying to retrieve the metadata of a layer of an image. |
|
| 278 |
+ ErrorCodeGetLayerMetadata = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 279 |
+ Value: "GETLAYERMETADATA", |
|
| 280 |
+ Message: "Failed to get layer metadata - %s", |
|
| 281 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 282 |
+ }) |
|
| 283 |
+ |
|
| 284 |
+ // ErrorCodeEmptyConfig is generated when the input config data |
|
| 285 |
+ // is empty. |
|
| 286 |
+ ErrorCodeEmptyConfig = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 287 |
+ Value: "EMPTYCONFIG", |
|
| 288 |
+ Message: "Config cannot be empty in order to create a container", |
|
| 289 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 290 |
+ }) |
|
| 291 |
+ |
|
| 292 |
+ // ErrorCodeNoSuchImageHash is generated when we can't find the |
|
| 293 |
+ // specified image by its hash |
|
| 294 |
+ ErrorCodeNoSuchImageHash = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 295 |
+ Value: "NOSUCHIMAGEHASH", |
|
| 296 |
+ Message: "No such image: %s", |
|
| 297 |
+ HTTPStatusCode: http.StatusNotFound, |
|
| 298 |
+ }) |
|
| 299 |
+ |
|
| 300 |
+ // ErrorCodeNoSuchImageTag is generated when we can't find the |
|
| 301 |
+ // specified image byt its name/tag. |
|
| 302 |
+ ErrorCodeNoSuchImageTag = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 303 |
+ Value: "NOSUCHIMAGETAG", |
|
| 304 |
+ Message: "No such image: %s:%s", |
|
| 305 |
+ HTTPStatusCode: http.StatusNotFound, |
|
| 306 |
+ }) |
|
| 307 |
+ |
|
| 308 |
+ // ErrorCodeMountOverFile is generated when we try to mount a volume |
|
| 309 |
+ // over an existing file (but not a dir). |
|
| 310 |
+ ErrorCodeMountOverFile = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 311 |
+ Value: "MOUNTOVERFILE", |
|
| 312 |
+ Message: "cannot mount volume over existing file, file exists %s", |
|
| 313 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 314 |
+ }) |
|
| 315 |
+ |
|
| 316 |
+ // ErrorCodeMountSetup is generated when we can't define a mount point |
|
| 317 |
+ // due to the source and destination are defined. |
|
| 318 |
+ ErrorCodeMountSetup = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 319 |
+ Value: "MOUNTSETUP", |
|
| 320 |
+ Message: "Unable to setup mount point, neither source nor volume defined", |
|
| 321 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 322 |
+ }) |
|
| 323 |
+ |
|
| 324 |
+ // ErrorCodeVolumeInvalidMode is generated when we the mode of a volume |
|
| 325 |
+ // mount is invalid. |
|
| 326 |
+ ErrorCodeVolumeInvalidMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 327 |
+ Value: "VOLUMEINVALIDMODE", |
|
| 328 |
+ Message: "invalid mode for volumes-from: %s", |
|
| 329 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 330 |
+ }) |
|
| 331 |
+ |
|
| 332 |
+ // ErrorCodeVolumeInvalid is generated when the format fo the |
|
| 333 |
+ // volume specification isn't valid. |
|
| 334 |
+ ErrorCodeVolumeInvalid = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 335 |
+ Value: "VOLUMEINVALID", |
|
| 336 |
+ Message: "Invalid volume specification: %s", |
|
| 337 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 338 |
+ }) |
|
| 339 |
+ |
|
| 340 |
+ // ErrorCodeVolumeAbs is generated when path to a volume isn't absolute. |
|
| 341 |
+ ErrorCodeVolumeAbs = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 342 |
+ Value: "VOLUMEABS", |
|
| 343 |
+ Message: "Invalid volume destination path: %s mount path must be absolute.", |
|
| 344 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 345 |
+ }) |
|
| 346 |
+ |
|
| 347 |
+ // ErrorCodeVolumeFromBlank is generated when path to a volume is blank. |
|
| 348 |
+ ErrorCodeVolumeFromBlank = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 349 |
+ Value: "VOLUMEFROMBLANK", |
|
| 350 |
+ Message: "malformed volumes-from specification: %s", |
|
| 351 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 352 |
+ }) |
|
| 353 |
+ |
|
| 354 |
+ // ErrorCodeVolumeMode is generated when 'mode' for a volume |
|
| 355 |
+ // isn't a valid. |
|
| 356 |
+ ErrorCodeVolumeMode = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 357 |
+ Value: "VOLUMEMODE", |
|
| 358 |
+ Message: "invalid mode for volumes-from: %s", |
|
| 359 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 360 |
+ }) |
|
| 361 |
+ |
|
| 362 |
+ // ErrorCodeVolumeDup is generated when we try to mount two volumes |
|
| 363 |
+ // to the same path. |
|
| 364 |
+ ErrorCodeVolumeDup = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 365 |
+ Value: "VOLUMEDUP", |
|
| 366 |
+ Message: "Duplicate bind mount %s", |
|
| 367 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 368 |
+ }) |
|
| 369 |
+ |
|
| 370 |
+ // ErrorCodeCantUnpause is generated when there's an error while trying |
|
| 371 |
+ // to unpause a container. |
|
| 372 |
+ ErrorCodeCantUnpause = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 373 |
+ Value: "CANTUNPAUSE", |
|
| 374 |
+ Message: "Cannot unpause container %s: %s", |
|
| 375 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 376 |
+ }) |
|
| 377 |
+ |
|
| 378 |
+ // ErrorCodePSError is generated when trying to run 'ps'. |
|
| 379 |
+ ErrorCodePSError = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 380 |
+ Value: "PSError", |
|
| 381 |
+ Message: "Error running ps: %s", |
|
| 382 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 383 |
+ }) |
|
| 384 |
+ |
|
| 385 |
+ // ErrorCodeNoPID is generated when looking for the PID field in the |
|
| 386 |
+ // ps output. |
|
| 387 |
+ ErrorCodeNoPID = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 388 |
+ Value: "NOPID", |
|
| 389 |
+ Message: "Couldn't find PID field in ps output", |
|
| 390 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 391 |
+ }) |
|
| 392 |
+ |
|
| 393 |
+ // ErrorCodeBadPID is generated when we can't convert a PID to an int. |
|
| 394 |
+ ErrorCodeBadPID = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 395 |
+ Value: "BADPID", |
|
| 396 |
+ Message: "Unexpected pid '%s': %s", |
|
| 397 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 398 |
+ }) |
|
| 399 |
+ |
|
| 400 |
+ // ErrorCodeNoTop is generated when we try to run 'top' but can't |
|
| 401 |
+ // because we're on windows. |
|
| 402 |
+ ErrorCodeNoTop = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 403 |
+ Value: "NOTOP", |
|
| 404 |
+ Message: "Top is not supported on Windows", |
|
| 405 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 406 |
+ }) |
|
| 407 |
+ |
|
| 408 |
+ // ErrorCodeStopped is generated when we try to stop a container |
|
| 409 |
+ // that is already stopped. |
|
| 410 |
+ ErrorCodeStopped = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 411 |
+ Value: "STOPPED", |
|
| 412 |
+ Message: "Container already stopped", |
|
| 413 |
+ HTTPStatusCode: http.StatusNotModified, |
|
| 414 |
+ }) |
|
| 415 |
+ |
|
| 416 |
+ // ErrorCodeCantStop is generated when we try to stop a container |
|
| 417 |
+ // but failed for some reason. |
|
| 418 |
+ ErrorCodeCantStop = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 419 |
+ Value: "CANTSTOP", |
|
| 420 |
+ Message: "Cannot stop container %s: %s\n", |
|
| 421 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 422 |
+ }) |
|
| 423 |
+ |
|
| 424 |
+ // ErrorCodeBadCPUFields is generated the number of CPU fields is |
|
| 425 |
+ // less than 8. |
|
| 426 |
+ ErrorCodeBadCPUFields = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 427 |
+ Value: "BADCPUFIELDS", |
|
| 428 |
+ Message: "invalid number of cpu fields", |
|
| 429 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 430 |
+ }) |
|
| 431 |
+ |
|
| 432 |
+ // ErrorCodeBadCPUInt is generated the CPU field can't be parsed as an int. |
|
| 433 |
+ ErrorCodeBadCPUInt = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 434 |
+ Value: "BADCPUINT", |
|
| 435 |
+ Message: "Unable to convert value %s to int: %s", |
|
| 436 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 437 |
+ }) |
|
| 438 |
+ |
|
| 439 |
+ // ErrorCodeBadStatFormat is generated the output of the stat info |
|
| 440 |
+ // isn't parseable. |
|
| 441 |
+ ErrorCodeBadStatFormat = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 442 |
+ Value: "BADSTATFORMAT", |
|
| 443 |
+ Message: "invalid stat format", |
|
| 444 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 445 |
+ }) |
|
| 446 |
+ |
|
| 447 |
+ // ErrorCodeTimedOut is generated when a timer expires. |
|
| 448 |
+ ErrorCodeTimedOut = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 449 |
+ Value: "TIMEDOUT", |
|
| 450 |
+ Message: "Timed out: %v", |
|
| 451 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 452 |
+ }) |
|
| 453 |
+ |
|
| 454 |
+ // ErrorCodeAlreadyRemoving is generated when we try to remove a |
|
| 455 |
+ // container that is already being removed. |
|
| 456 |
+ ErrorCodeAlreadyRemoving = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 457 |
+ Value: "ALREADYREMOVING", |
|
| 458 |
+ Message: "Status is already RemovalInProgress", |
|
| 459 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 460 |
+ }) |
|
| 461 |
+ |
|
| 462 |
+ // ErrorCodeStartPaused is generated when we start a paused container. |
|
| 463 |
+ ErrorCodeStartPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 464 |
+ Value: "STARTPAUSED", |
|
| 465 |
+ Message: "Cannot start a paused container, try unpause instead.", |
|
| 466 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 467 |
+ }) |
|
| 468 |
+ |
|
| 469 |
+ // ErrorCodeAlreadyStarted is generated when we try to start a container |
|
| 470 |
+ // that is already running. |
|
| 471 |
+ ErrorCodeAlreadyStarted = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 472 |
+ Value: "ALREADYSTARTED", |
|
| 473 |
+ Message: "Container already started", |
|
| 474 |
+ HTTPStatusCode: http.StatusNotModified, |
|
| 475 |
+ }) |
|
| 476 |
+ |
|
| 477 |
+ // ErrorCodeHostConfigStart is generated when a HostConfig is passed |
|
| 478 |
+ // into the start command. |
|
| 479 |
+ ErrorCodeHostConfigStart = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 480 |
+ Value: "HOSTCONFIGSTART", |
|
| 481 |
+ Message: "Supplying a hostconfig on start is not supported. It should be supplied on create", |
|
| 482 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 483 |
+ }) |
|
| 484 |
+ |
|
| 485 |
+ // ErrorCodeCantStart is generated when an error occurred while |
|
| 486 |
+ // trying to start a container. |
|
| 487 |
+ ErrorCodeCantStart = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
|
| 488 |
+ Value: "CANTSTART", |
|
| 489 |
+ Message: "Cannot start container %s: %s", |
|
| 490 |
+ HTTPStatusCode: http.StatusInternalServerError, |
|
| 491 |
+ }) |
|
| 21 | 492 |
) |
| ... | ... |
@@ -12,12 +12,15 @@ import ( |
| 12 | 12 |
"golang.org/x/net/websocket" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/Sirupsen/logrus" |
| 15 |
+ "github.com/docker/distribution/registry/api/errcode" |
|
| 16 |
+ derr "github.com/docker/docker/api/errors" |
|
| 15 | 17 |
"github.com/docker/docker/api/types" |
| 16 | 18 |
"github.com/docker/docker/context" |
| 17 | 19 |
"github.com/docker/docker/daemon" |
| 18 | 20 |
"github.com/docker/docker/pkg/ioutils" |
| 19 | 21 |
"github.com/docker/docker/pkg/signal" |
| 20 | 22 |
"github.com/docker/docker/runconfig" |
| 23 |
+ "github.com/docker/docker/utils" |
|
| 21 | 24 |
) |
| 22 | 25 |
|
| 23 | 26 |
func (s *Server) getContainersJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| ... | ... |
@@ -144,7 +147,7 @@ func (s *Server) getContainersLogs(ctx context.Context, w http.ResponseWriter, r |
| 144 | 144 |
// The client may be expecting all of the data we're sending to |
| 145 | 145 |
// be multiplexed, so send it through OutStream, which will |
| 146 | 146 |
// have been set up to handle that if needed. |
| 147 |
- fmt.Fprintf(logsConfig.OutStream, "Error running logs job: %s\n", err) |
|
| 147 |
+ fmt.Fprintf(logsConfig.OutStream, "Error running logs job: %s\n", utils.GetErrorMessage(err)) |
|
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
return nil |
| ... | ... |
@@ -184,10 +187,6 @@ func (s *Server) postContainersStart(ctx context.Context, w http.ResponseWriter, |
| 184 | 184 |
} |
| 185 | 185 |
|
| 186 | 186 |
if err := s.daemon.ContainerStart(vars["name"], hostConfig); err != nil {
|
| 187 |
- if err.Error() == "Container already started" {
|
|
| 188 |
- w.WriteHeader(http.StatusNotModified) |
|
| 189 |
- return nil |
|
| 190 |
- } |
|
| 191 | 187 |
return err |
| 192 | 188 |
} |
| 193 | 189 |
w.WriteHeader(http.StatusNoContent) |
| ... | ... |
@@ -205,10 +204,6 @@ func (s *Server) postContainersStop(ctx context.Context, w http.ResponseWriter, |
| 205 | 205 |
seconds, _ := strconv.Atoi(r.Form.Get("t"))
|
| 206 | 206 |
|
| 207 | 207 |
if err := s.daemon.ContainerStop(vars["name"], seconds); err != nil {
|
| 208 |
- if err.Error() == "Container already stopped" {
|
|
| 209 |
- w.WriteHeader(http.StatusNotModified) |
|
| 210 |
- return nil |
|
| 211 |
- } |
|
| 212 | 208 |
return err |
| 213 | 209 |
} |
| 214 | 210 |
w.WriteHeader(http.StatusNoContent) |
| ... | ... |
@@ -236,7 +231,9 @@ func (s *Server) postContainersKill(ctx context.Context, w http.ResponseWriter, |
| 236 | 236 |
} |
| 237 | 237 |
|
| 238 | 238 |
if err := s.daemon.ContainerKill(name, uint64(sig)); err != nil {
|
| 239 |
- _, isStopped := err.(daemon.ErrContainerNotRunning) |
|
| 239 |
+ theErr, isDerr := err.(errcode.ErrorCoder) |
|
| 240 |
+ isStopped := isDerr && theErr.ErrorCode() == derr.ErrorCodeNotRunning |
|
| 241 |
+ |
|
| 240 | 242 |
// Return error that's not caused because the container is stopped. |
| 241 | 243 |
// Return error if the container is not running and the api is >= 1.20 |
| 242 | 244 |
// to keep backwards compatibility. |
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
"github.com/opencontainers/runc/libcontainer/label" |
| 16 | 16 |
|
| 17 | 17 |
"github.com/Sirupsen/logrus" |
| 18 |
+ derr "github.com/docker/docker/api/errors" |
|
| 18 | 19 |
"github.com/docker/docker/daemon/execdriver" |
| 19 | 20 |
"github.com/docker/docker/daemon/logger" |
| 20 | 21 |
"github.com/docker/docker/daemon/logger/jsonfilelog" |
| ... | ... |
@@ -39,15 +40,6 @@ var ( |
| 39 | 39 |
ErrRootFSReadOnly = errors.New("container rootfs is marked read-only")
|
| 40 | 40 |
) |
| 41 | 41 |
|
| 42 |
-// ErrContainerNotRunning holds the id of the container that is not running. |
|
| 43 |
-type ErrContainerNotRunning struct {
|
|
| 44 |
- id string |
|
| 45 |
-} |
|
| 46 |
- |
|
| 47 |
-func (e ErrContainerNotRunning) Error() string {
|
|
| 48 |
- return fmt.Sprintf("Container %s is not running", e.id)
|
|
| 49 |
-} |
|
| 50 |
- |
|
| 51 | 42 |
type streamConfig struct {
|
| 52 | 43 |
stdout *broadcastwriter.BroadcastWriter |
| 53 | 44 |
stderr *broadcastwriter.BroadcastWriter |
| ... | ... |
@@ -229,7 +221,7 @@ func (container *Container) getRootResourcePath(path string) (string, error) {
|
| 229 | 229 |
|
| 230 | 230 |
func (container *Container) exportContainerRw() (archive.Archive, error) {
|
| 231 | 231 |
if container.daemon == nil {
|
| 232 |
- return nil, fmt.Errorf("Can't load storage driver for unregistered container %s", container.ID)
|
|
| 232 |
+ return nil, derr.ErrorCodeUnregisteredContainer.WithArgs(container.ID) |
|
| 233 | 233 |
} |
| 234 | 234 |
archive, err := container.daemon.diff(container) |
| 235 | 235 |
if err != nil {
|
| ... | ... |
@@ -255,7 +247,7 @@ func (container *Container) Start() (err error) {
|
| 255 | 255 |
} |
| 256 | 256 |
|
| 257 | 257 |
if container.removalInProgress || container.Dead {
|
| 258 |
- return fmt.Errorf("Container is marked for removal and cannot be started.")
|
|
| 258 |
+ return derr.ErrorCodeContainerBeingRemoved |
|
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 | 261 |
// if we encounter an error during start we need to ensure that any other |
| ... | ... |
@@ -381,11 +373,11 @@ func (container *Container) killSig(sig int) error {
|
| 381 | 381 |
|
| 382 | 382 |
// We could unpause the container for them rather than returning this error |
| 383 | 383 |
if container.Paused {
|
| 384 |
- return fmt.Errorf("Container %s is paused. Unpause the container before stopping", container.ID)
|
|
| 384 |
+ return derr.ErrorCodeUnpauseContainer.WithArgs(container.ID) |
|
| 385 | 385 |
} |
| 386 | 386 |
|
| 387 | 387 |
if !container.Running {
|
| 388 |
- return ErrContainerNotRunning{container.ID}
|
|
| 388 |
+ return derr.ErrorCodeNotRunning.WithArgs(container.ID) |
|
| 389 | 389 |
} |
| 390 | 390 |
|
| 391 | 391 |
// signal to the monitor that it should not restart the container |
| ... | ... |
@@ -422,12 +414,12 @@ func (container *Container) pause() error {
|
| 422 | 422 |
|
| 423 | 423 |
// We cannot Pause the container which is not running |
| 424 | 424 |
if !container.Running {
|
| 425 |
- return ErrContainerNotRunning{container.ID}
|
|
| 425 |
+ return derr.ErrorCodeNotRunning.WithArgs(container.ID) |
|
| 426 | 426 |
} |
| 427 | 427 |
|
| 428 | 428 |
// We cannot Pause the container which is already paused |
| 429 | 429 |
if container.Paused {
|
| 430 |
- return fmt.Errorf("Container %s is already paused", container.ID)
|
|
| 430 |
+ return derr.ErrorCodeAlreadyPaused.WithArgs(container.ID) |
|
| 431 | 431 |
} |
| 432 | 432 |
|
| 433 | 433 |
if err := container.daemon.execDriver.Pause(container.command); err != nil {
|
| ... | ... |
@@ -444,12 +436,12 @@ func (container *Container) unpause() error {
|
| 444 | 444 |
|
| 445 | 445 |
// We cannot unpause the container which is not running |
| 446 | 446 |
if !container.Running {
|
| 447 |
- return ErrContainerNotRunning{container.ID}
|
|
| 447 |
+ return derr.ErrorCodeNotRunning.WithArgs(container.ID) |
|
| 448 | 448 |
} |
| 449 | 449 |
|
| 450 | 450 |
// We cannot unpause the container which is not paused |
| 451 | 451 |
if !container.Paused {
|
| 452 |
- return fmt.Errorf("Container %s is not paused", container.ID)
|
|
| 452 |
+ return derr.ErrorCodeNotPaused.WithArgs(container.ID) |
|
| 453 | 453 |
} |
| 454 | 454 |
|
| 455 | 455 |
if err := container.daemon.execDriver.Unpause(container.command); err != nil {
|
| ... | ... |
@@ -463,7 +455,7 @@ func (container *Container) unpause() error {
|
| 463 | 463 |
// Kill forcefully terminates a container. |
| 464 | 464 |
func (container *Container) Kill() error {
|
| 465 | 465 |
if !container.IsRunning() {
|
| 466 |
- return ErrContainerNotRunning{container.ID}
|
|
| 466 |
+ return derr.ErrorCodeNotRunning.WithArgs(container.ID) |
|
| 467 | 467 |
} |
| 468 | 468 |
|
| 469 | 469 |
// 1. Send SIGKILL |
| ... | ... |
@@ -556,7 +548,7 @@ func (container *Container) Restart(seconds int) error {
|
| 556 | 556 |
// to the given height and width. The container must be running. |
| 557 | 557 |
func (container *Container) Resize(h, w int) error {
|
| 558 | 558 |
if !container.IsRunning() {
|
| 559 |
- return ErrContainerNotRunning{container.ID}
|
|
| 559 |
+ return derr.ErrorCodeNotRunning.WithArgs(container.ID) |
|
| 560 | 560 |
} |
| 561 | 561 |
if err := container.command.ProcessConfig.Terminal.Resize(h, w); err != nil {
|
| 562 | 562 |
return err |
| ... | ... |
@@ -597,7 +589,7 @@ func (container *Container) changes() ([]archive.Change, error) {
|
| 597 | 597 |
|
| 598 | 598 |
func (container *Container) getImage() (*image.Image, error) {
|
| 599 | 599 |
if container.daemon == nil {
|
| 600 |
- return nil, fmt.Errorf("Can't get image of unregistered container")
|
|
| 600 |
+ return nil, derr.ErrorCodeImageUnregContainer |
|
| 601 | 601 |
} |
| 602 | 602 |
return container.daemon.graph.Get(container.ImageID) |
| 603 | 603 |
} |
| ... | ... |
@@ -624,7 +616,7 @@ func (container *Container) rootfsPath() string {
|
| 624 | 624 |
|
| 625 | 625 |
func validateID(id string) error {
|
| 626 | 626 |
if id == "" {
|
| 627 |
- return fmt.Errorf("Invalid empty id")
|
|
| 627 |
+ return derr.ErrorCodeEmptyID |
|
| 628 | 628 |
} |
| 629 | 629 |
return nil |
| 630 | 630 |
} |
| ... | ... |
@@ -722,7 +714,7 @@ func (container *Container) getLogger() (logger.Logger, error) {
|
| 722 | 722 |
} |
| 723 | 723 |
c, err := logger.GetLogDriver(cfg.Type) |
| 724 | 724 |
if err != nil {
|
| 725 |
- return nil, fmt.Errorf("Failed to get logging factory: %v", err)
|
|
| 725 |
+ return nil, derr.ErrorCodeLoggingFactory.WithArgs(err) |
|
| 726 | 726 |
} |
| 727 | 727 |
ctx := logger.Context{
|
| 728 | 728 |
Config: cfg.Config, |
| ... | ... |
@@ -753,7 +745,7 @@ func (container *Container) startLogging() error {
|
| 753 | 753 |
|
| 754 | 754 |
l, err := container.getLogger() |
| 755 | 755 |
if err != nil {
|
| 756 |
- return fmt.Errorf("Failed to initialize logging driver: %v", err)
|
|
| 756 |
+ return derr.ErrorCodeInitLogger.WithArgs(err) |
|
| 757 | 757 |
} |
| 758 | 758 |
|
| 759 | 759 |
copier := logger.NewCopier(container.ID, map[string]io.Reader{"stdout": container.StdoutPipe(), "stderr": container.StderrPipe()}, l)
|
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
"time" |
| 16 | 16 |
|
| 17 | 17 |
"github.com/Sirupsen/logrus" |
| 18 |
+ derr "github.com/docker/docker/api/errors" |
|
| 18 | 19 |
"github.com/docker/docker/daemon/execdriver" |
| 19 | 20 |
"github.com/docker/docker/daemon/links" |
| 20 | 21 |
"github.com/docker/docker/daemon/network" |
| ... | ... |
@@ -86,7 +87,7 @@ func (container *Container) setupLinkedContainers() ([]string, error) {
|
| 86 | 86 |
if len(children) > 0 {
|
| 87 | 87 |
for linkAlias, child := range children {
|
| 88 | 88 |
if !child.IsRunning() {
|
| 89 |
- return nil, fmt.Errorf("Cannot link to a non running container: %s AS %s", child.Name, linkAlias)
|
|
| 89 |
+ return nil, derr.ErrorCodeLinkNotRunning.WithArgs(child.Name, linkAlias) |
|
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 | 92 |
link := links.NewLink( |
| ... | ... |
@@ -168,7 +169,7 @@ func getDevicesFromPath(deviceMapping runconfig.DeviceMapping) (devs []*configs. |
| 168 | 168 |
return devs, nil |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 |
- return devs, fmt.Errorf("error gathering device information while adding custom device %q: %s", deviceMapping.PathOnHost, err)
|
|
| 171 |
+ return devs, derr.ErrorCodeDeviceInfo.WithArgs(deviceMapping.PathOnHost, err) |
|
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 | 174 |
func populateCommand(c *Container, env []string) error {
|
| ... | ... |
@@ -511,11 +512,11 @@ func (container *Container) buildSandboxOptions() ([]libnetwork.SandboxOption, e |
| 511 | 511 |
|
| 512 | 512 |
func (container *Container) buildPortMapInfo(ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
|
| 513 | 513 |
if ep == nil {
|
| 514 |
- return nil, fmt.Errorf("invalid endpoint while building port map info")
|
|
| 514 |
+ return nil, derr.ErrorCodeEmptyEndpoint |
|
| 515 | 515 |
} |
| 516 | 516 |
|
| 517 | 517 |
if networkSettings == nil {
|
| 518 |
- return nil, fmt.Errorf("invalid networksettings while building port map info")
|
|
| 518 |
+ return nil, derr.ErrorCodeEmptyNetwork |
|
| 519 | 519 |
} |
| 520 | 520 |
|
| 521 | 521 |
driverInfo, err := ep.DriverInfo() |
| ... | ... |
@@ -539,7 +540,7 @@ func (container *Container) buildPortMapInfo(ep libnetwork.Endpoint, networkSett |
| 539 | 539 |
for _, tp := range exposedPorts {
|
| 540 | 540 |
natPort, err := nat.NewPort(tp.Proto.String(), strconv.Itoa(int(tp.Port))) |
| 541 | 541 |
if err != nil {
|
| 542 |
- return nil, fmt.Errorf("Error parsing Port value(%v):%v", tp.Port, err)
|
|
| 542 |
+ return nil, derr.ErrorCodeParsingPort.WithArgs(tp.Port, err) |
|
| 543 | 543 |
} |
| 544 | 544 |
networkSettings.Ports[natPort] = nil |
| 545 | 545 |
} |
| ... | ... |
@@ -567,11 +568,11 @@ func (container *Container) buildPortMapInfo(ep libnetwork.Endpoint, networkSett |
| 567 | 567 |
|
| 568 | 568 |
func (container *Container) buildEndpointInfo(ep libnetwork.Endpoint, networkSettings *network.Settings) (*network.Settings, error) {
|
| 569 | 569 |
if ep == nil {
|
| 570 |
- return nil, fmt.Errorf("invalid endpoint while building port map info")
|
|
| 570 |
+ return nil, derr.ErrorCodeEmptyEndpoint |
|
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 | 573 |
if networkSettings == nil {
|
| 574 |
- return nil, fmt.Errorf("invalid networksettings while building port map info")
|
|
| 574 |
+ return nil, derr.ErrorCodeEmptyNetwork |
|
| 575 | 575 |
} |
| 576 | 576 |
|
| 577 | 577 |
epInfo := ep.Info() |
| ... | ... |
@@ -648,16 +649,16 @@ func (container *Container) updateNetwork() error {
|
| 648 | 648 |
|
| 649 | 649 |
sb, err := ctrl.SandboxByID(sid) |
| 650 | 650 |
if err != nil {
|
| 651 |
- return fmt.Errorf("error locating sandbox id %s: %v", sid, err)
|
|
| 651 |
+ return derr.ErrorCodeNoSandbox.WithArgs(sid, err) |
|
| 652 | 652 |
} |
| 653 | 653 |
|
| 654 | 654 |
options, err := container.buildSandboxOptions() |
| 655 | 655 |
if err != nil {
|
| 656 |
- return fmt.Errorf("Update network failed: %v", err)
|
|
| 656 |
+ return derr.ErrorCodeNetworkUpdate.WithArgs(err) |
|
| 657 | 657 |
} |
| 658 | 658 |
|
| 659 | 659 |
if err := sb.Refresh(options...); err != nil {
|
| 660 |
- return fmt.Errorf("Update network failed: Failure in refresh sandbox %s: %v", sid, err)
|
|
| 660 |
+ return derr.ErrorCodeNetworkRefresh.WithArgs(sid, err) |
|
| 661 | 661 |
} |
| 662 | 662 |
|
| 663 | 663 |
return nil |
| ... | ... |
@@ -711,7 +712,7 @@ func (container *Container) buildCreateEndpointOptions() ([]libnetwork.EndpointO |
| 711 | 711 |
portStart, portEnd, err = newP.Range() |
| 712 | 712 |
} |
| 713 | 713 |
if err != nil {
|
| 714 |
- return nil, fmt.Errorf("Error parsing HostPort value(%s):%v", binding[i].HostPort, err)
|
|
| 714 |
+ return nil, derr.ErrorCodeHostPort.WithArgs(binding[i].HostPort, err) |
|
| 715 | 715 |
} |
| 716 | 716 |
pbCopy.HostPort = uint16(portStart) |
| 717 | 717 |
pbCopy.HostPortEnd = uint16(portEnd) |
| ... | ... |
@@ -812,7 +813,7 @@ func (container *Container) allocateNetwork() error {
|
| 812 | 812 |
networkDriver = controller.Config().Daemon.DefaultDriver |
| 813 | 813 |
} |
| 814 | 814 |
} else if service != "" {
|
| 815 |
- return fmt.Errorf("conflicting options: publishing a service and network mode")
|
|
| 815 |
+ return derr.ErrorCodeNetworkConflict |
|
| 816 | 816 |
} |
| 817 | 817 |
|
| 818 | 818 |
if runconfig.NetworkMode(networkDriver).IsBridge() && container.daemon.configStore.DisableBridge {
|
| ... | ... |
@@ -903,7 +904,7 @@ func (container *Container) configureNetwork(networkName, service, networkDriver |
| 903 | 903 |
} |
| 904 | 904 |
|
| 905 | 905 |
if err := container.updateJoinInfo(ep); err != nil {
|
| 906 |
- return fmt.Errorf("Updating join info failed: %v", err)
|
|
| 906 |
+ return derr.ErrorCodeJoinInfo.WithArgs(err) |
|
| 907 | 907 |
} |
| 908 | 908 |
|
| 909 | 909 |
return nil |
| ... | ... |
@@ -954,7 +955,7 @@ func (container *Container) getIpcContainer() (*Container, error) {
|
| 954 | 954 |
return nil, err |
| 955 | 955 |
} |
| 956 | 956 |
if !c.IsRunning() {
|
| 957 |
- return nil, fmt.Errorf("cannot join IPC of a non running container: %s", containerID)
|
|
| 957 |
+ return nil, derr.ErrorCodeIPCRunning |
|
| 958 | 958 |
} |
| 959 | 959 |
return c, nil |
| 960 | 960 |
} |
| ... | ... |
@@ -979,7 +980,7 @@ func (container *Container) setupWorkingDirectory() error {
|
| 979 | 979 |
} |
| 980 | 980 |
} |
| 981 | 981 |
if pthInfo != nil && !pthInfo.IsDir() {
|
| 982 |
- return fmt.Errorf("Cannot mkdir: %s is not a directory", container.Config.WorkingDir)
|
|
| 982 |
+ return derr.ErrorCodeNotADir.WithArgs(container.Config.WorkingDir) |
|
| 983 | 983 |
} |
| 984 | 984 |
} |
| 985 | 985 |
return nil |
| ... | ... |
@@ -990,21 +991,21 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
|
| 990 | 990 |
switch parts[0] {
|
| 991 | 991 |
case "container": |
| 992 | 992 |
if len(parts) != 2 {
|
| 993 |
- return nil, fmt.Errorf("no container specified to join network")
|
|
| 993 |
+ return nil, derr.ErrorCodeParseContainer |
|
| 994 | 994 |
} |
| 995 | 995 |
nc, err := container.daemon.Get(parts[1]) |
| 996 | 996 |
if err != nil {
|
| 997 | 997 |
return nil, err |
| 998 | 998 |
} |
| 999 | 999 |
if container == nc {
|
| 1000 |
- return nil, fmt.Errorf("cannot join own network")
|
|
| 1000 |
+ return nil, derr.ErrorCodeJoinSelf |
|
| 1001 | 1001 |
} |
| 1002 | 1002 |
if !nc.IsRunning() {
|
| 1003 |
- return nil, fmt.Errorf("cannot join network of a non running container: %s", parts[1])
|
|
| 1003 |
+ return nil, derr.ErrorCodeJoinRunning.WithArgs(parts[1]) |
|
| 1004 | 1004 |
} |
| 1005 | 1005 |
return nc, nil |
| 1006 | 1006 |
default: |
| 1007 |
- return nil, fmt.Errorf("network mode not set to container")
|
|
| 1007 |
+ return nil, derr.ErrorCodeModeNotContainer |
|
| 1008 | 1008 |
} |
| 1009 | 1009 |
} |
| 1010 | 1010 |
|
| ... | ... |
@@ -1200,7 +1201,7 @@ func (container *Container) removeMountPoints(rm bool) error {
|
| 1200 | 1200 |
} |
| 1201 | 1201 |
} |
| 1202 | 1202 |
if len(rmErrors) > 0 {
|
| 1203 |
- return fmt.Errorf("Error removing volumes:\n%v", strings.Join(rmErrors, "\n"))
|
|
| 1203 |
+ return derr.ErrorCodeRemovingVolume.WithArgs(strings.Join(rmErrors, "\n")) |
|
| 1204 | 1204 |
} |
| 1205 | 1205 |
return nil |
| 1206 | 1206 |
} |
| ... | ... |
@@ -3,9 +3,9 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "fmt" |
|
| 7 | 6 |
"strings" |
| 8 | 7 |
|
| 8 |
+ derr "github.com/docker/docker/api/errors" |
|
| 9 | 9 |
"github.com/docker/docker/daemon/execdriver" |
| 10 | 10 |
) |
| 11 | 11 |
|
| ... | ... |
@@ -64,7 +64,7 @@ func populateCommand(c *Container, env []string) error {
|
| 64 | 64 |
} |
| 65 | 65 |
} |
| 66 | 66 |
default: |
| 67 |
- return fmt.Errorf("invalid network mode: %s", c.hostConfig.NetworkMode)
|
|
| 67 |
+ return derr.ErrorCodeInvalidNetworkMode.WithArgs(c.hostConfig.NetworkMode) |
|
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
pid := &execdriver.Pid{}
|
| ... | ... |
@@ -90,22 +90,22 @@ func populateCommand(c *Container, env []string) error {
|
| 90 | 90 |
var layerPaths []string |
| 91 | 91 |
img, err := c.daemon.graph.Get(c.ImageID) |
| 92 | 92 |
if err != nil {
|
| 93 |
- return fmt.Errorf("Failed to graph.Get on ImageID %s - %s", c.ImageID, err)
|
|
| 93 |
+ return derr.ErrorCodeGetGraph.WithArgs(c.ImageID, err) |
|
| 94 | 94 |
} |
| 95 | 95 |
for i := img; i != nil && err == nil; i, err = c.daemon.graph.GetParent(i) {
|
| 96 | 96 |
lp, err := c.daemon.driver.Get(i.ID, "") |
| 97 | 97 |
if err != nil {
|
| 98 |
- return fmt.Errorf("Failed to get layer path from graphdriver %s for ImageID %s - %s", c.daemon.driver.String(), i.ID, err)
|
|
| 98 |
+ return derr.ErrorCodeGetLayer.WithArgs(c.daemon.driver.String(), i.ID, err) |
|
| 99 | 99 |
} |
| 100 | 100 |
layerPaths = append(layerPaths, lp) |
| 101 | 101 |
err = c.daemon.driver.Put(i.ID) |
| 102 | 102 |
if err != nil {
|
| 103 |
- return fmt.Errorf("Failed to put layer path from graphdriver %s for ImageID %s - %s", c.daemon.driver.String(), i.ID, err)
|
|
| 103 |
+ return derr.ErrorCodePutLayer.WithArgs(c.daemon.driver.String(), i.ID, err) |
|
| 104 | 104 |
} |
| 105 | 105 |
} |
| 106 | 106 |
m, err := c.daemon.driver.GetMetadata(c.ID) |
| 107 | 107 |
if err != nil {
|
| 108 |
- return fmt.Errorf("Failed to get layer metadata - %s", err)
|
|
| 108 |
+ return derr.ErrorCodeGetLayerMetadata.WithArgs(err) |
|
| 109 | 109 |
} |
| 110 | 110 |
layerFolder := m["dir"] |
| 111 | 111 |
|
| ... | ... |
@@ -1,10 +1,10 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"strings" |
| 6 | 5 |
|
| 7 | 6 |
"github.com/Sirupsen/logrus" |
| 7 |
+ derr "github.com/docker/docker/api/errors" |
|
| 8 | 8 |
"github.com/docker/docker/api/types" |
| 9 | 9 |
"github.com/docker/docker/graph/tags" |
| 10 | 10 |
"github.com/docker/docker/image" |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
// ContainerCreate takes configs and creates a container. |
| 18 | 18 |
func (daemon *Daemon) ContainerCreate(name string, config *runconfig.Config, hostConfig *runconfig.HostConfig, adjustCPUShares bool) (*Container, []string, error) {
|
| 19 | 19 |
if config == nil {
|
| 20 |
- return nil, nil, fmt.Errorf("Config cannot be empty in order to create a container")
|
|
| 20 |
+ return nil, nil, derr.ErrorCodeEmptyConfig |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
warnings, err := daemon.verifyContainerSettings(hostConfig, config) |
| ... | ... |
@@ -31,13 +31,13 @@ func (daemon *Daemon) ContainerCreate(name string, config *runconfig.Config, hos |
| 31 | 31 |
if err != nil {
|
| 32 | 32 |
if daemon.Graph().IsNotExist(err, config.Image) {
|
| 33 | 33 |
if strings.Contains(config.Image, "@") {
|
| 34 |
- return nil, warnings, fmt.Errorf("No such image: %s", config.Image)
|
|
| 34 |
+ return nil, warnings, derr.ErrorCodeNoSuchImageHash.WithArgs(config.Image) |
|
| 35 | 35 |
} |
| 36 | 36 |
img, tag := parsers.ParseRepositoryTag(config.Image) |
| 37 | 37 |
if tag == "" {
|
| 38 | 38 |
tag = tags.DefaultTag |
| 39 | 39 |
} |
| 40 |
- return nil, warnings, fmt.Errorf("No such image: %s:%s", img, tag)
|
|
| 40 |
+ return nil, warnings, derr.ErrorCodeNoSuchImageTag.WithArgs(img, tag) |
|
| 41 | 41 |
} |
| 42 | 42 |
return nil, warnings, err |
| 43 | 43 |
} |
| ... | ... |
@@ -3,11 +3,11 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "fmt" |
|
| 7 | 6 |
"os" |
| 8 | 7 |
"path/filepath" |
| 9 | 8 |
"strings" |
| 10 | 9 |
|
| 10 |
+ derr "github.com/docker/docker/api/errors" |
|
| 11 | 11 |
"github.com/docker/docker/image" |
| 12 | 12 |
"github.com/docker/docker/pkg/stringid" |
| 13 | 13 |
"github.com/docker/docker/runconfig" |
| ... | ... |
@@ -41,7 +41,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco |
| 41 | 41 |
|
| 42 | 42 |
stat, err := os.Stat(path) |
| 43 | 43 |
if err == nil && !stat.IsDir() {
|
| 44 |
- return fmt.Errorf("cannot mount volume over existing file, file exists %s", path)
|
|
| 44 |
+ return derr.ErrorCodeMountOverFile.WithArgs(path) |
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 | 47 |
volumeDriver := hostConfig.VolumeDriver |
| ... | ... |
@@ -1,10 +1,11 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"runtime" |
| 6 | 5 |
|
| 6 |
+ derr "github.com/docker/docker/api/errors" |
|
| 7 | 7 |
"github.com/docker/docker/runconfig" |
| 8 |
+ "github.com/docker/docker/utils" |
|
| 8 | 9 |
) |
| 9 | 10 |
|
| 10 | 11 |
// ContainerStart starts a container. |
| ... | ... |
@@ -15,11 +16,11 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf |
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 | 17 |
if container.isPaused() {
|
| 18 |
- return fmt.Errorf("Cannot start a paused container, try unpause instead.")
|
|
| 18 |
+ return derr.ErrorCodeStartPaused |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
if container.IsRunning() {
|
| 22 |
- return fmt.Errorf("Container already started")
|
|
| 22 |
+ return derr.ErrorCodeAlreadyStarted |
|
| 23 | 23 |
} |
| 24 | 24 |
|
| 25 | 25 |
// Windows does not have the backwards compatibility issue here. |
| ... | ... |
@@ -33,7 +34,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf |
| 33 | 33 |
} |
| 34 | 34 |
} else {
|
| 35 | 35 |
if hostConfig != nil {
|
| 36 |
- return fmt.Errorf("Supplying a hostconfig on start is not supported. It should be supplied on create")
|
|
| 36 |
+ return derr.ErrorCodeHostConfigStart |
|
| 37 | 37 |
} |
| 38 | 38 |
} |
| 39 | 39 |
|
| ... | ... |
@@ -44,7 +45,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConf |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 | 46 |
if err := container.Start(); err != nil {
|
| 47 |
- return fmt.Errorf("Cannot start container %s: %s", name, err)
|
|
| 47 |
+ return derr.ErrorCodeCantStart.WithArgs(name, utils.GetErrorMessage(err)) |
|
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
return nil |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"sync" |
| 6 | 6 |
"time" |
| 7 | 7 |
|
| 8 |
+ derr "github.com/docker/docker/api/errors" |
|
| 8 | 9 |
"github.com/docker/docker/daemon/execdriver" |
| 9 | 10 |
"github.com/docker/docker/pkg/units" |
| 10 | 11 |
) |
| ... | ... |
@@ -111,7 +112,7 @@ func wait(waitChan <-chan struct{}, timeout time.Duration) error {
|
| 111 | 111 |
} |
| 112 | 112 |
select {
|
| 113 | 113 |
case <-time.After(timeout): |
| 114 |
- return fmt.Errorf("Timed out: %v", timeout)
|
|
| 114 |
+ return derr.ErrorCodeTimedOut.WithArgs(timeout) |
|
| 115 | 115 |
case <-waitChan: |
| 116 | 116 |
return nil |
| 117 | 117 |
} |
| ... | ... |
@@ -251,7 +252,7 @@ func (s *State) setRemovalInProgress() error {
|
| 251 | 251 |
s.Lock() |
| 252 | 252 |
defer s.Unlock() |
| 253 | 253 |
if s.removalInProgress {
|
| 254 |
- return fmt.Errorf("Status is already RemovalInProgress")
|
|
| 254 |
+ return derr.ErrorCodeAlreadyRemoving |
|
| 255 | 255 |
} |
| 256 | 256 |
s.removalInProgress = true |
| 257 | 257 |
return nil |
| ... | ... |
@@ -4,7 +4,6 @@ package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"bufio" |
| 7 |
- "fmt" |
|
| 8 | 7 |
"os" |
| 9 | 8 |
"strconv" |
| 10 | 9 |
"strings" |
| ... | ... |
@@ -12,6 +11,7 @@ import ( |
| 12 | 12 |
"time" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/Sirupsen/logrus" |
| 15 |
+ derr "github.com/docker/docker/api/errors" |
|
| 15 | 16 |
"github.com/docker/docker/daemon/execdriver" |
| 16 | 17 |
"github.com/docker/docker/pkg/pubsub" |
| 17 | 18 |
"github.com/opencontainers/runc/libcontainer/system" |
| ... | ... |
@@ -154,13 +154,13 @@ func (s *statsCollector) getSystemCPUUsage() (uint64, error) {
|
| 154 | 154 |
switch parts[0] {
|
| 155 | 155 |
case "cpu": |
| 156 | 156 |
if len(parts) < 8 {
|
| 157 |
- return 0, fmt.Errorf("invalid number of cpu fields")
|
|
| 157 |
+ return 0, derr.ErrorCodeBadCPUFields |
|
| 158 | 158 |
} |
| 159 | 159 |
var totalClockTicks uint64 |
| 160 | 160 |
for _, i := range parts[1:8] {
|
| 161 | 161 |
v, err := strconv.ParseUint(i, 10, 64) |
| 162 | 162 |
if err != nil {
|
| 163 |
- return 0, fmt.Errorf("Unable to convert value %s to int: %s", i, err)
|
|
| 163 |
+ return 0, derr.ErrorCodeBadCPUInt.WithArgs(i, err) |
|
| 164 | 164 |
} |
| 165 | 165 |
totalClockTicks += v |
| 166 | 166 |
} |
| ... | ... |
@@ -168,5 +168,5 @@ func (s *statsCollector) getSystemCPUUsage() (uint64, error) {
|
| 168 | 168 |
s.clockTicksPerSecond, nil |
| 169 | 169 |
} |
| 170 | 170 |
} |
| 171 |
- return 0, fmt.Errorf("invalid stat format")
|
|
| 171 |
+ return 0, derr.ErrorCodeBadStatFormat |
|
| 172 | 172 |
} |
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 |
-import "fmt" |
|
| 3 |
+import ( |
|
| 4 |
+ derr "github.com/docker/docker/api/errors" |
|
| 5 |
+) |
|
| 4 | 6 |
|
| 5 | 7 |
// ContainerStop looks for the given container and terminates it, |
| 6 | 8 |
// waiting the given number of seconds before forcefully killing the |
| ... | ... |
@@ -14,10 +16,10 @@ func (daemon *Daemon) ContainerStop(name string, seconds int) error {
|
| 14 | 14 |
return err |
| 15 | 15 |
} |
| 16 | 16 |
if !container.IsRunning() {
|
| 17 |
- return fmt.Errorf("Container already stopped")
|
|
| 17 |
+ return derr.ErrorCodeStopped |
|
| 18 | 18 |
} |
| 19 | 19 |
if err := container.Stop(seconds); err != nil {
|
| 20 |
- return fmt.Errorf("Cannot stop container %s: %s\n", name, err)
|
|
| 20 |
+ return derr.ErrorCodeCantStop.WithArgs(name, err) |
|
| 21 | 21 |
} |
| 22 | 22 |
return nil |
| 23 | 23 |
} |
| ... | ... |
@@ -3,11 +3,11 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "fmt" |
|
| 7 | 6 |
"os/exec" |
| 8 | 7 |
"strconv" |
| 9 | 8 |
"strings" |
| 10 | 9 |
|
| 10 |
+ derr "github.com/docker/docker/api/errors" |
|
| 11 | 11 |
"github.com/docker/docker/api/types" |
| 12 | 12 |
) |
| 13 | 13 |
|
| ... | ... |
@@ -27,7 +27,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
if !container.IsRunning() {
|
| 30 |
- return nil, fmt.Errorf("Container %s is not running", name)
|
|
| 30 |
+ return nil, derr.ErrorCodeNotRunning.WithArgs(name) |
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
pids, err := daemon.ExecutionDriver().GetPidsForContainer(container.ID) |
| ... | ... |
@@ -37,7 +37,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container |
| 37 | 37 |
|
| 38 | 38 |
output, err := exec.Command("ps", strings.Split(psArgs, " ")...).Output()
|
| 39 | 39 |
if err != nil {
|
| 40 |
- return nil, fmt.Errorf("Error running ps: %s", err)
|
|
| 40 |
+ return nil, derr.ErrorCodePSError.WithArgs(err) |
|
| 41 | 41 |
} |
| 42 | 42 |
|
| 43 | 43 |
procList := &types.ContainerProcessList{}
|
| ... | ... |
@@ -52,7 +52,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container |
| 52 | 52 |
} |
| 53 | 53 |
} |
| 54 | 54 |
if pidIndex == -1 {
|
| 55 |
- return nil, fmt.Errorf("Couldn't find PID field in ps output")
|
|
| 55 |
+ return nil, derr.ErrorCodeNoPID |
|
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
// loop through the output and extract the PID from each line |
| ... | ... |
@@ -63,7 +63,7 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.Container |
| 63 | 63 |
fields := strings.Fields(line) |
| 64 | 64 |
p, err := strconv.Atoi(fields[pidIndex]) |
| 65 | 65 |
if err != nil {
|
| 66 |
- return nil, fmt.Errorf("Unexpected pid '%s': %s", fields[pidIndex], err)
|
|
| 66 |
+ return nil, derr.ErrorCodeBadPID.WithArgs(fields[pidIndex], err) |
|
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 | 69 |
for _, pid := range pids {
|
| ... | ... |
@@ -1,12 +1,11 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 |
- |
|
| 4 |
+ derr "github.com/docker/docker/api/errors" |
|
| 6 | 5 |
"github.com/docker/docker/api/types" |
| 7 | 6 |
) |
| 8 | 7 |
|
| 9 | 8 |
// ContainerTop is not supported on Windows and returns an error. |
| 10 | 9 |
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*types.ContainerProcessList, error) {
|
| 11 |
- return nil, fmt.Errorf("Top is not supported on Windows")
|
|
| 10 |
+ return nil, derr.ErrorCodeNoTop |
|
| 12 | 11 |
} |
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 |
-import "fmt" |
|
| 3 |
+import ( |
|
| 4 |
+ derr "github.com/docker/docker/api/errors" |
|
| 5 |
+) |
|
| 4 | 6 |
|
| 5 | 7 |
// ContainerUnpause unpauses a container |
| 6 | 8 |
func (daemon *Daemon) ContainerUnpause(name string) error {
|
| ... | ... |
@@ -10,7 +12,7 @@ func (daemon *Daemon) ContainerUnpause(name string) error {
|
| 10 | 10 |
} |
| 11 | 11 |
|
| 12 | 12 |
if err := container.unpause(); err != nil {
|
| 13 |
- return fmt.Errorf("Cannot unpause container %s: %s", name, err)
|
|
| 13 |
+ return derr.ErrorCodeCantUnpause.WithArgs(name, err) |
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 | 16 |
return nil |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"sync" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/Sirupsen/logrus" |
| 13 |
+ derr "github.com/docker/docker/api/errors" |
|
| 13 | 14 |
"github.com/docker/docker/api/types" |
| 14 | 15 |
"github.com/docker/docker/pkg/chrootarchive" |
| 15 | 16 |
"github.com/docker/docker/pkg/system" |
| ... | ... |
@@ -59,7 +60,7 @@ func (m *mountPoint) Setup() (string, error) {
|
| 59 | 59 |
return m.Source, nil |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
- return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
|
|
| 62 |
+ return "", derr.ErrorCodeMountSetup |
|
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 | 65 |
// hasResource checks whether the given absolute path for a container is in |
| ... | ... |
@@ -3,7 +3,6 @@ |
| 3 | 3 |
package daemon |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "fmt" |
|
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"os" |
| 9 | 8 |
"path/filepath" |
| ... | ... |
@@ -11,6 +10,7 @@ import ( |
| 11 | 11 |
"strings" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/Sirupsen/logrus" |
| 14 |
+ derr "github.com/docker/docker/api/errors" |
|
| 14 | 15 |
"github.com/docker/docker/daemon/execdriver" |
| 15 | 16 |
"github.com/docker/docker/pkg/system" |
| 16 | 17 |
"github.com/docker/docker/runconfig" |
| ... | ... |
@@ -72,18 +72,18 @@ func parseBindMount(spec, volumeDriver string) (*mountPoint, error) {
|
| 72 | 72 |
bind.Destination = arr[1] |
| 73 | 73 |
mode := arr[2] |
| 74 | 74 |
if !volume.ValidMountMode(mode) {
|
| 75 |
- return nil, fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
|
| 75 |
+ return nil, derr.ErrorCodeVolumeInvalidMode.WithArgs(mode) |
|
| 76 | 76 |
} |
| 77 | 77 |
bind.RW = volume.ReadWrite(mode) |
| 78 | 78 |
// Mode field is used by SELinux to decide whether to apply label |
| 79 | 79 |
bind.Mode = mode |
| 80 | 80 |
default: |
| 81 |
- return nil, fmt.Errorf("Invalid volume specification: %s", spec)
|
|
| 81 |
+ return nil, derr.ErrorCodeVolumeInvalid.WithArgs(spec) |
|
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 | 84 |
//validate the volumes destination path |
| 85 | 85 |
if !filepath.IsAbs(bind.Destination) {
|
| 86 |
- return nil, fmt.Errorf("Invalid volume destination path: %s mount path must be absolute.", bind.Destination)
|
|
| 86 |
+ return nil, derr.ErrorCodeVolumeAbs.WithArgs(bind.Destination) |
|
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 | 89 |
name, source, err := parseVolumeSource(arr[0]) |
| ... | ... |
@@ -263,7 +263,7 @@ func (daemon *Daemon) verifyVolumesInfo(container *Container) error {
|
| 263 | 263 |
// parseVolumesFrom ensure that the supplied volumes-from is valid. |
| 264 | 264 |
func parseVolumesFrom(spec string) (string, string, error) {
|
| 265 | 265 |
if len(spec) == 0 {
|
| 266 |
- return "", "", fmt.Errorf("malformed volumes-from specification: %s", spec)
|
|
| 266 |
+ return "", "", derr.ErrorCodeVolumeFromBlank.WithArgs(spec) |
|
| 267 | 267 |
} |
| 268 | 268 |
|
| 269 | 269 |
specParts := strings.SplitN(spec, ":", 2) |
| ... | ... |
@@ -273,7 +273,7 @@ func parseVolumesFrom(spec string) (string, string, error) {
|
| 273 | 273 |
if len(specParts) == 2 {
|
| 274 | 274 |
mode = specParts[1] |
| 275 | 275 |
if !volume.ValidMountMode(mode) {
|
| 276 |
- return "", "", fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
|
| 276 |
+ return "", "", derr.ErrorCodeVolumeMode.WithArgs(mode) |
|
| 277 | 277 |
} |
| 278 | 278 |
} |
| 279 | 279 |
return id, mode, nil |
| ... | ... |
@@ -336,7 +336,7 @@ func (daemon *Daemon) registerMountPoints(container *Container, hostConfig *runc |
| 336 | 336 |
} |
| 337 | 337 |
|
| 338 | 338 |
if binds[bind.Destination] {
|
| 339 |
- return fmt.Errorf("Duplicate bind mount %s", bind.Destination)
|
|
| 339 |
+ return derr.ErrorCodeVolumeDup.WithArgs(bind.Destination) |
|
| 340 | 340 |
} |
| 341 | 341 |
|
| 342 | 342 |
if len(bind.Name) > 0 && len(bind.Driver) > 0 {
|
| ... | ... |
@@ -3000,7 +3000,7 @@ func (s *DockerSuite) TestRunContainerNetworkModeToSelf(c *check.C) {
|
| 3000 | 3000 |
testRequires(c, DaemonIsLinux) |
| 3001 | 3001 |
out, _, err := dockerCmdWithError("run", "--name=me", "--net=container:me", "busybox", "true")
|
| 3002 | 3002 |
if err == nil || !strings.Contains(out, "cannot join own network") {
|
| 3003 |
- c.Fatalf("using container net mode to self should result in an error")
|
|
| 3003 |
+ c.Fatalf("using container net mode to self should result in an error\nerr: %q\nout: %s", err, out)
|
|
| 3004 | 3004 |
} |
| 3005 | 3005 |
} |
| 3006 | 3006 |
|