summaryrefslogtreecommitdiff
path: root/errors
Commit message (Collapse)AuthorAgeFilesLines
* Remove static errors from errors package.David Calavera2016-02-267-1235/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Moving all strings to the errors package wasn't a good idea after all. Our custom implementation of Go errors predates everything that's nice and good about working with errors in Go. Take as an example what we have to do to get an error message: ```go func GetErrorMessage(err error) string { switch err.(type) { case errcode.Error: e, _ := err.(errcode.Error) return e.Message case errcode.ErrorCode: ec, _ := err.(errcode.ErrorCode) return ec.Message() default: return err.Error() } } ``` This goes against every good practice for Go development. The language already provides a simple, intuitive and standard way to get error messages, that is calling the `Error()` method from an error. Reinventing the error interface is a mistake. Our custom implementation also makes very hard to reason about errors, another nice thing about Go. I found several (>10) error declarations that we don't use anywhere. This is a clear sign about how little we know about the errors we return. I also found several error usages where the number of arguments was different than the parameters declared in the error, another clear example of how difficult is to reason about errors. Moreover, our custom implementation didn't really make easier for people to return custom HTTP status code depending on the errors. Again, it's hard to reason about when to set custom codes and how. Take an example what we have to do to extract the message and status code from an error before returning a response from the API: ```go switch err.(type) { case errcode.ErrorCode: daError, _ := err.(errcode.ErrorCode) statusCode = daError.Descriptor().HTTPStatusCode errMsg = daError.Message() case errcode.Error: // For reference, if you're looking for a particular error // then you can do something like : // import ( derr "github.com/docker/docker/errors" ) // if daError.ErrorCode() == derr.ErrorCodeNoSuchContainer { ... } daError, _ := err.(errcode.Error) statusCode = daError.ErrorCode().Descriptor().HTTPStatusCode errMsg = daError.Message default: // This part of will be removed once we've // converted everything over to use the errcode package // FIXME: this is brittle and should not be necessary. // If we need to differentiate between different possible error types, // we should create appropriate error types with clearly defined meaning errStr := strings.ToLower(err.Error()) for keyword, status := range map[string]int{ "not found": http.StatusNotFound, "no such": http.StatusNotFound, "bad parameter": http.StatusBadRequest, "conflict": http.StatusConflict, "impossible": http.StatusNotAcceptable, "wrong login/password": http.StatusUnauthorized, "hasn't been activated": http.StatusForbidden, } { if strings.Contains(errStr, keyword) { statusCode = status break } } } ``` You can notice two things in that code: 1. We have to explain how errors work, because our implementation goes against how easy to use Go errors are. 2. At no moment we arrived to remove that `switch` statement that was the original reason to use our custom implementation. This change removes all our status errors from the errors package and puts them back in their specific contexts. IT puts the messages back with their contexts. That way, we know right away when errors used and how to generate their messages. It uses custom interfaces to reason about errors. Errors that need to response with a custom status code MUST implementent this simple interface: ```go type errorWithStatus interface { HTTPErrorStatusCode() int } ``` This interface is very straightforward to implement. It also preserves Go errors real behavior, getting the message is as simple as using the `Error()` method. I included helper functions to generate errors that use custom status code in `errors/errors.go`. By doing this, we remove the hard dependency we have eeverywhere to our custom errors package. Yes, you can use it as a helper to generate error, but it's still very easy to generate errors without it. Please, read this fantastic blog post about errors in Go: http://dave.cheney.net/2014/12/24/inspecting-errors Signed-off-by: David Calavera <david.calavera@gmail.com>
* fix docshuqun2016-02-191-1/+1
| | | Signed-off-by: huqun <huqun@zju.edu.cn>
* Fix error for restarting containerZhang Wei2016-02-041-3/+3
| | | | | | | Fix error message for `--net container:b` and `--ipc container:b`, container `b` is a restarting container. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
* Merge pull request #19959 from WeiZhang555/fix-cli-print-errAlexander Morozov2016-02-031-4/+30
|\ | | | | Remove redundant error message
| * Remove redundant error messageZhang Wei2016-02-031-4/+30
| | | | | | | | | | | | | | | | | | Currently some commands including `kill`, `pause`, `restart`, `rm`, `rmi`, `stop`, `unpause`, `udpate`, `wait` will print a lot of error message on client side, with a lot of redundant messages, this commit is trying to remove the unuseful and redundant information for user. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
* | Fix docker top a restarting containerLei Jitang2016-02-021-9/+9
|/ | | | Signed-off-by: Lei Jitang <leijitang@huawei.com>
* Forbid exec a restarting containerZhang Wei2016-01-271-0/+9
| | | | | | | | | | | Currently if we exec a restarting container, client will fail silently, and daemon will print error that container can't be found which is not a very meaningful prompt to user. This commit will stop user from exec a restarting container and gives more explicit error message. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
* Reject multiple networks on container creationAlessandro Boch2016-01-251-0/+9
| | | | Signed-off-by: Alessandro Boch <aboch@docker.com>
* Fix panic on starting exec more than onceBrian Goff2016-01-151-0/+9
| | | | | | | | | | | Issue was caused when exec is tarted, exits, then stated again. In this case, `Close` is called twice, which closes a channel twice. Changes execConfig.ExitCode to a pointer so we can test if the it has been set or not. This allows us to return early when the exec has already been run. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
* Add docker network connect/disconnect to non-running containerLei Jitang2016-01-111-0/+9
| | | | Signed-off-by: Lei Jitang <leijitang@huawei.com>
* Move responsibility of ls/inspect to volume driverBrian Goff2016-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | Makes `docker volume ls` and `docker volume inspect` ask the volume drivers rather than only using what is cached locally. Previously in order to use a volume from an external driver, one would either have to use `docker volume create` or have a container that is already using that volume for it to be visible to the other volume API's. For keeping uniqueness of volume names in the daemon, names are bound to a driver on a first come first serve basis. If two drivers have a volume with the same name, the first one is chosen, and a warning is logged about the second one. Adds 2 new methods to the plugin API, `List` and `Get`. If a plugin does not implement these endpoints, a user will not be able to find the specified volumes as well requests go through the drivers. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
* Add network events.David Calavera2015-12-301-0/+9
| | | | Signed-off-by: David Calavera <david.calavera@gmail.com>
* Remove `IsPaused` from backend interface.David Calavera2015-12-211-0/+9
| | | | | | Move connection hijacking logic to the daemon. Signed-off-by: David Calavera <david.calavera@gmail.com>
* Fix typos found across repositoryJustas Brazauskas2015-12-131-1/+1
| | | | Signed-off-by: Justas Brazauskas <brazauskasjustas@gmail.com>
* Correct the message of ErrorCodeNoSuchContainer to "No such container"Wen Cheng Ma2015-12-041-1/+1
| | | | | | Fixes issue #18424 Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
* This patch adds --tmpfs as a option for mounting tmpfs on directoriesDan Walsh2015-12-021-5/+5
| | | | | | | | | It will Tar up contents of child directory onto tmpfs if mounted over This patch will use the new PreMount and PostMount hooks to "tar" up the contents of the base image on top of tmpfs mount points. Signed-off-by: Dan Walsh <dwalsh@redhat.com>
* Update daemon and docker core to use new content addressable storageTonis Tiigi2015-11-241-9/+0
| | | | | | | | | | | | | | | | | Add distribution package for managing pulls and pushes. This is based on the old code in the graph package, with major changes to work with the new image/layer model. Add v1 migration code. Update registry, api/*, and daemon packages to use the reference package's types where applicable. Update daemon package to use image/layer/tag stores instead of the graph package Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com> Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
* fix docZhang Kun2015-11-151-1/+1
| | | | | | | | Signed-off-by: Zhang Kun <zkazure@gmail.com> fix doc Signed-off-by: Zhang Kun <zkazure@gmail.com>
* Typo s/contained/containerJohn Howard2015-11-081-7/+7
| | | | Signed-off-by: John Howard <jhoward@microsoft.com>
* Merge pull request #17383 from Microsoft/10662-volumeerrorsBrian Goff2015-11-051-9/+9
|\ | | | | Fix volume error messages
| * Fix volume error messagesJohn Howard2015-10-281-9/+9
| | | | | | | | Signed-off-by: John Howard <jhoward@microsoft.com>
* | Change 'docker run' exit codes to distinguish docker/contained errorsSally O'Malley2015-11-041-9/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The purpose of this PR is for users to distinguish Docker errors from contained command errors. This PR modifies 'docker run' exit codes to follow the chroot standard for exit codes. Exit status: 125 if 'docker run' itself fails 126 if contained command cannot be invoked 127 if contained command cannot be found the exit status otherwise Signed-off-by: Sally O'Malley <somalley@redhat.com>
* | Add show error when attach to a paused containerLei Jitang2015-10-281-0/+8
|/ | | | Signed-off-by: Lei Jitang <leijitang@huawei.com>
* Windows: Add volume supportJohn Howard2015-10-221-12/+54
| | | | Signed-off-by: John Howard <jhoward@microsoft.com>
* Move volume name validation to the local driver.David Calavera2015-10-211-4/+4
| | | | | | | | | Delegate validation tasks to the volume drivers. It's up to them to decide whether a name is valid or not. Restrict volume names for the local driver to prevent creating mount points outside docker's volumes directory. Signed-off-by: David Calavera <david.calavera@gmail.com>
* validate the name of named volumexlgao-zju2015-10-201-0/+8
| | | | Signed-off-by: xlgao-zju <xlgao@zju.edu.cn>
* Return 404 for all network operations without network controller.David Calavera2015-10-191-0/+9
| | | | | | | | This will prevent the api from trying to serve network requests in systems where libnetwork is not enabled, returning 404 responses in any case. Signed-off-by: David Calavera <david.calavera@gmail.com>
* volume create error on conflict optionKun Zhang2015-10-121-0/+9
| | | | Signed-off-by: Kun Zhang <zkazure@gmail.com>
* Make exec start return proper error codesBrian Goff2015-10-021-2/+2
| | | | | | | | | | | | Exec start was sending HTTP 500 for every error. Fixed an error where pausing a container and then calling exec start caused the daemon to freeze. Updated API docs which incorrectly showed that a successful exec start was an HTTP 201, in reality it is HTTP 200. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
* Validate --cpuset-cpus, --cpuset-memsAntonio Murdaca2015-09-271-0/+36
| | | | | | | | | | Before this patch libcontainer badly errored out with `invalid argument` or `numerical result out of range` while trying to write to cpuset.cpus or cpuset.mems with an invalid value provided. This patch adds validation to --cpuset-cpus and --cpuset-mems flag along with validation based on system's available cpus/mems before starting a container. Signed-off-by: Antonio Murdaca <runcom@linux.com>
* Merge pull request #16411 from duglin/DaemonErrorsBrian Goff2015-09-231-5/+343
|\ | | | | Move more 'daemon' errors to the new error package
| * Move more 'daemon' errors to the new error packageDoug Davis2015-09-231-5/+343
| | | | | | | | Signed-off-by: Doug Davis <dug@us.ibm.com>
* | Adding error codes to image packageSrini Brahmaroutu2015-09-231-0/+20
|/ | | | Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
* Organize server pre-func logic in middlewares.David Calavera2015-09-211-0/+27
| | | | | | | It defines global middlewares for every request. This makes the server slightly more composable. Signed-off-by: David Calavera <david.calavera@gmail.com>
* Move api/errors/ to errors/Doug Davis2015-09-174-0/+649
Per @calavera's suggestion: https://github.com/docker/docker/pull/16355#issuecomment-141139220 Signed-off-by: Doug Davis <dug@us.ibm.com>