1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
Commit graph

14 commits

Author SHA1 Message Date
Sebastiaan van Stijn
81dbed4c8b
Merge pull request #39527 from thaJeztah/pull_platform_regression
Fix error handling of incorrect --platform values
2019-07-16 03:29:16 +02:00
Sebastiaan van Stijn
9d1b4f5fc3
Add regression tests for invalid platform status codes
Before we handled containerd errors, using an invalid platform produced a 500 status:

```bash
curl -v \
  -X POST \
  --unix-socket /var/run/docker.sock \
  "http://localhost:2375/v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest" \
  -H "Content-Type: application/json"
```

```
* Connected to localhost (docker.sock) port 80 (#0)
> POST /v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest HTTP/1.1
> Host: localhost:2375
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 500 Internal Server Error
< Api-Version: 1.40
< Content-Length: 85
< Content-Type: application/json
< Date: Mon, 15 Jul 2019 15:25:44 GMT
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/19.03.0-rc2 (linux)
<
{"message":"\"foobar\": unknown operating system or architecture: invalid argument"}
```

That problem is now fixed, and the API correctly returns a 4xx status:

```bash
curl -v \
  -X POST \
  --unix-socket /var/run/docker.sock \
  "http://localhost:2375/v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest" \
  -H "Content-Type: application/json"
```

```
* Connected to localhost (/var/run/docker.sock) port 80 (#0)
> POST /v1.40/images/create?fromImage=hello-world&platform=foobar&tag=latest HTTP/1.1
> Host: localhost:2375
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 400 Bad Request
< Api-Version: 1.41
< Content-Type: application/json
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Mon, 15 Jul 2019 15:13:42 GMT
< Content-Length: 85
<
{"message":"\"foobar\": unknown operating system or architecture: invalid argument"}
* Curl_http_done: called premature == 0
```

This patch adds tests to validate the behaviour

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-07-15 20:37:00 +02:00
Sebastiaan van Stijn
4a516215e2
errdefs: convert containerd errors to the correct status code
In situations where the containerd error is consumed directly
and not received over gRPC, errors were not translated.

This patch converts containerd errors to the correct HTTP
status code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-07-15 20:36:57 +02:00
Sebastiaan van Stijn
32f4fdfb5c
errdefs: remove unneeded recursive calls
The `statusCodeFromGRPCError` and `statusCodeFromDistributionError`
helpers are used by `GetHTTPErrorStatusCode`, which already recurses
if the error implements the `Causer` interface.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-07-15 18:22:19 +02:00
Sebastiaan van Stijn
7d4b788381 errdefs: remove "ErrAlreadyExists" because it's not an error
The `ErrAlreadyExists` error is used for 304 statuses, which
is not an error-condition, so should probably not be defined
as part of the errdefs package.

This patch removes the `ErrAlreadyExists` interface, and related
helpers, as it was currently not used.

Note that a 304 status can fulfil certain use-cases, but (refering
to https://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html)
could probably be handled by a 200 OK, unless we want to perform
caching in the client.

If we do want to use 304 statuses, perhaps we need a separate class
of "errors" for this (?).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-21 21:25:15 +00:00
Sebastiaan van Stijn
2a9c987e5a
Move httputils error helpers to errdefs package
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-16 00:42:23 +01:00
Sebastiaan van Stijn
264775b52b
Make errdefs helpers idempotent
Don't convert errors if they already have the right type

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-01-03 11:16:01 +01:00
Sebastiaan van Stijn
43a8ec654b
Add missing nil-check on errdefs.Unavailable()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-12-30 15:18:57 +01:00
Kazuhiro Sera
1e49fdcafc Fix the several typos detected by github.com/client9/misspell
Signed-off-by: Kazuhiro Sera <seratch@gmail.com>
2018-08-09 00:45:00 +09:00
ohbarye
0f95b23d98 Fix typos: remove duplicated "the"
Signed-off-by: Masato Ohba <over.rye@gmail.com>
2018-05-17 21:49:51 +09:00
Sebastiaan van Stijn
d48392a35b
Fix definition of ErrSystem type
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-03-05 23:42:23 +01:00
Sebastiaan van Stijn
59854e407d
Change return for errdefs.getImplementer()
The types defined in the errdefs package do not
satisfy the `error` interface, because they do not
implement `Error()`.

Instead of returning the matched interface, return
the original error.

When matching _multiple_ interfaces/types, Golang doesn't complain:

    func getImplementer(err error) error {
        switch e := err.(type) {
        case
            ErrNotFound,
            ErrInvalidParameter:
            return e
        default:
            return err
        }
    }

But matching a single interface/type:

    func getImplementer(err error) error {
        switch e := err.(type) {
        case
            ErrNotFound:
            return e
        default:
            return err
        }
    }

Produces an error:

    cannot use e (type ErrNotFound) as type error in return argument: ErrNotFound does not implement error (missing Error method)

Return the original `err` instead of the matched interface/type instead.

Also added some additional tests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-03-05 23:41:58 +01:00
Daniel Nephin
4f0d95fa6e Add canonical import comment
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-05 16:51:57 -05:00
Brian Goff
d453fe35b9 Move api/errdefs to errdefs
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-01-11 21:21:43 -05:00