Commit Graph

35 Commits

Author SHA1 Message Date
b2ac99b3fa Remove static errors from errors package.
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>
Upstream-commit: a793564b2591035aec5412fbcbcccf220c773a4c
Component: engine
2016-02-26 15:49:09 -05:00
831079c48f fix docs
Signed-off-by: huqun  <huqun@zju.edu.cn>
Upstream-commit: b96bbf26dbce9ca60e54e4bb734b8574642e3026
Component: engine
2016-02-19 13:51:14 +08:00
4aae2e5565 Fix error for restarting container
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>
Upstream-commit: 3c0a91d227a04e146d24e35d2f71d8c5343cfc77
Component: engine
2016-02-04 20:14:50 +08:00
5649ae9668 Merge pull request #19959 from WeiZhang555/fix-cli-print-err
Remove redundant error message
Upstream-commit: 28a7577a029780e4533faf3d057ec9f6c7a10948
Component: engine
2016-02-03 10:56:19 -08:00
68f96de053 Remove redundant error message
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>
Upstream-commit: 894266c1bbdfeb53bf278f3cb762945bac69e592
Component: engine
2016-02-03 15:45:20 +08:00
0c9780ee15 Fix docker top a restarting container
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: 5566ccb7aa0747005573f6f4f04f46552b75a394
Component: engine
2016-02-02 21:05:01 -05:00
1083d494cd Forbid exec a restarting container
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>
Upstream-commit: 1d2208fed90da9ab72ded3b1c65bb2a71b66ce93
Component: engine
2016-01-27 10:05:06 +08:00
fc335b54af Reject multiple networks on container creation
Signed-off-by: Alessandro Boch <aboch@docker.com>
Upstream-commit: cfa515fd9d1530bd84e98c6d6564e641dcb2d0fe
Component: engine
2016-01-25 12:50:01 -08:00
addf165927 Fix panic on starting exec more than once
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>
Upstream-commit: 1a60a805bfabee729dbc833515cd0be439adb95b
Component: engine
2016-01-15 11:57:23 -05:00
3b26d1d1d4 Add docker network connect/disconnect to non-running container
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: 79d4f0f56ec84922184e25c0263807158b6fb76b
Component: engine
2016-01-11 20:13:39 -05:00
db1910a30c Move responsibility of ls/inspect to volume driver
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>
Upstream-commit: d3eca4451d264aac564594fe46b8c097bd85a5cc
Component: engine
2016-01-05 16:28:38 -05:00
e32ea4c0f9 Add network events.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: f15af1eff75f920c956e7c437d1ef81f5c31129a
Component: engine
2015-12-30 17:39:33 -05:00
9e1ab087f5 Remove IsPaused from backend interface.
Move connection hijacking logic to the daemon.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: af94f941df9ee43b61e0e8f9d3c3b3962597eff6
Component: engine
2015-12-21 12:34:21 -05:00
3c4fcf6b7a Fix typos found across repository
Signed-off-by: Justas Brazauskas <brazauskasjustas@gmail.com>
Upstream-commit: 927b334ebfc786276a039e45ec097e71bf9a104c
Component: engine
2015-12-13 18:04:12 +02:00
cae2a5b6ac Correct the message of ErrorCodeNoSuchContainer to "No such container"
Fixes issue #18424

Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
Upstream-commit: c424c8c32c86d5e02964ad84802e9f9fa4e55522
Component: engine
2015-12-04 15:00:08 +08:00
71b21cf347 This patch adds --tmpfs as a option for mounting tmpfs on directories
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>
Upstream-commit: b3e527dfd242ad30c0297c8b257862116cf2c50e
Component: engine
2015-12-02 10:06:59 -05:00
e105a29374 Update daemon and docker core to use new content addressable storage
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>
Upstream-commit: 4352da7803d182a6013a5238ce20a7c749db979a
Component: engine
2015-11-24 09:40:25 -08:00
35adb0ee96 fix doc
Signed-off-by: Zhang Kun <zkazure@gmail.com>

fix doc

Signed-off-by: Zhang Kun <zkazure@gmail.com>
Upstream-commit: 82ba25bea9ae8412186e4cd1d3ba30e6a2072a26
Component: engine
2015-11-15 23:32:40 +08:00
56752590f4 Typo s/contained/container
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 2ff68910e2ac3e16d47de2b95a412e07586a7c60
Component: engine
2015-11-08 18:29:34 -08:00
920a8605ab Merge pull request #17383 from Microsoft/10662-volumeerrors
Fix volume error messages
Upstream-commit: f1834153de196361e14c86b12c98d6b118cd4f56
Component: engine
2015-11-05 21:58:03 -05:00
f66555fbae Change 'docker run' exit codes to distinguish docker/contained errors
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>
Upstream-commit: 41de7a18d8f231568977e66bb58a6a02545d49d9
Component: engine
2015-11-04 15:18:50 -05:00
8ca5c39620 Add show error when attach to a paused container
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: de1d611990a80cf4a38ec501469c08c1aeee2d60
Component: engine
2015-10-28 21:00:09 -04:00
dd17d17d3e Fix volume error messages
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: 5f4cb33a5186c7822dc718ba915f59979c598c28
Component: engine
2015-10-28 09:23:43 -07:00
f7f7ce4926 Windows: Add volume support
Signed-off-by: John Howard <jhoward@microsoft.com>
Upstream-commit: a7e686a779523100a092acb2683b849126953931
Component: engine
2015-10-22 10:42:53 -07:00
f1b2a78ca3 Move volume name validation to the local driver.
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>
Upstream-commit: d6d60287ee3a8a064340582d65c131181ae77127
Component: engine
2015-10-21 12:28:26 -04:00
7cf93e47cd validate the name of named volume
Signed-off-by: xlgao-zju <xlgao@zju.edu.cn>
Upstream-commit: 609961ddcc835422e51ef4f3fd6088b96180f72f
Component: engine
2015-10-20 12:36:04 -04:00
b8b4d2b3f7 Return 404 for all network operations without network controller.
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>
Upstream-commit: eb982e7c00192c8306f9c420fb469f087c7b161d
Component: engine
2015-10-19 14:40:18 -04:00
6841b07f52 volume create error on conflict option
Signed-off-by: Kun Zhang <zkazure@gmail.com>
Upstream-commit: 0ff3123eba071166def8072d8c7f3aa9afa0b56f
Component: engine
2015-10-12 11:16:39 +08:00
a9fcaeb043 Make exec start return proper error codes
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>
Upstream-commit: 2d43d93410c29cec87deb9cd940c3b2a8af5fbbb
Component: engine
2015-10-02 14:40:22 -04:00
360eb92f7d Validate --cpuset-cpus, --cpuset-mems
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>
Upstream-commit: 94464e3a5e1dce0f6b3e821f79fe193278f67dba
Component: engine
2015-09-27 16:38:58 +02:00
8316b128fe Merge pull request #16411 from duglin/DaemonErrors
Move more 'daemon' errors to the new error package
Upstream-commit: ebe7ef9fc2238f008101f31c0c405cbc460ab757
Component: engine
2015-09-23 21:20:56 -04:00
71a51a6ff7 Adding error codes to image package
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
Upstream-commit: da0ca83377db0228db82b7be4096b34e3ebfb114
Component: engine
2015-09-23 17:03:37 +00:00
5ee0f81315 Move more 'daemon' errors to the new error package
Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 0a734182eb09497806a9ff3e1c8031ab1ab39f13
Component: engine
2015-09-23 09:51:45 -07:00
651f1e747f Organize server pre-func logic in middlewares.
It defines global middlewares for every request.
This makes the server slightly more composable.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 0fea04d27ee91d7b57e0a77b110db1c861768c74
Component: engine
2015-09-21 14:27:06 -04:00
3904dd3167 Move api/errors/ to errors/
Per @calavera's suggestion: https://github.com/docker/docker/pull/16355#issuecomment-141139220

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: a283a30fb026aad4434a9f2e34f7ce955d27a957
Component: engine
2015-09-17 11:54:14 -07:00