Skip to content

api: container, exec resize: improve errors for invalid width/height#48679

Merged
thaJeztah merged 6 commits intomoby:masterfrom
thaJeztah:resize_uint
Oct 17, 2024
Merged

api: container, exec resize: improve errors for invalid width/height#48679
thaJeztah merged 6 commits intomoby:masterfrom
thaJeztah:resize_uint

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

api/server/httputils: add Uint32Value utility

api: container resize: improve errors for invalid width/height

api: backend.ContainerResize: pass context and use uint32 for width, height

Containerd accepts uints for these, so make the backend signature align
with that, so that we don't have to cast values. Also pass the context
along.

api: exec resize: improve errors for invalid width/height

api: backend.ContainerExecResize: pass context and use uint32 for width, height

Containerd accepts uints for these, so make the backend signature align
with that, so that we don't have to cast values. Also pass the context
along.

client: ContainerResize, ContainerExecResize: don't overflow width/height

Mostly theoretical, but let's be correct here. It's worth noting that the API
(backend) accepts uint32, but container.ResizeOptions uses uint (uint64). We
could decide to add checks for this on the client side, or to change the
type (but that would be a breaking change).

- Description for the changelog

api: improve errors for invalid width/height on container resize and exec resize

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added area/api API status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. impact/api labels Oct 16, 2024
@thaJeztah thaJeztah added this to the 28.0.0 milestone Oct 16, 2024
@thaJeztah thaJeztah self-assigned this Oct 16, 2024
Comment thread api/server/httputils/form.go Outdated
@thaJeztah thaJeztah force-pushed the resize_uint branch 2 times, most recently from 863c8e0 to 71b7357 Compare October 16, 2024 22:52
Comment thread client/container_resize.go Outdated
Copy link
Copy Markdown
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread daemon/resize_test.go Outdated
Comment thread daemon/resize_test.go Outdated
Comment thread daemon/resize_test.go Outdated
return 0, errors.Unwrap(err)
}
if isNeg {
return 0, strconv.ErrRange
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW; I was on the fence whether to make this function return an errdefs.Invalid on its own, but as we will likely always wrap the error to decorate it with some message ("invalid XYZ"), it would be a bit double.

Doing decorating as part of this function would've worked, using the field name that's passed, but in the current uses, those fields would be w or h, which would be a bit too obscure for an error message, and I don't think we want to change the API to use ?width=xxx,height=xxx just for that purpose 😂

We can still consider doing so at some point though (to prevent consumers forgetting to add a errdefs type.

@thaJeztah
Copy link
Copy Markdown
Member Author

Rebased, and addressed the comments 👍

…height

Containerd accepts uints for these, so make the backend signature  align
with that, so that we don't have to cast values. Also pass the context
along.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
…th, height

Containerd accepts uints for these, so make the backend signature align
with that, so that we don't have to cast values. Also pass the context
along.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
…ight

Mostly theoretical, but let's be correct here. It's worth noting that the API
(backend) accepts uint32, but container.ResizeOptions uses uint (uint64). We
could decide to add checks for this on the client side, or to change the
type (but that would be a breaking change).

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Copy Markdown
Member Author

Are you OK, Docker Hub?

=== Failed
=== FAIL: amd64.integration.image TestImagePullNonExisting/asdfasdf (0.11s)
    pull_test.go:191: assertion failed: expected error to contain "pull access denied for asdfasdf, repository does not exist or may require 'docker login'", got "Error response from daemon: Get \"[https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest\](https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest/)": EOF"
        Error response from daemon: Get "https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest": EOF
    pull_test.go:192: assertion failed: error is Error response from daemon: Get "https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest": EOF (errdefs.errSystem), not errdefs.IsNotFound
    --- FAIL: TestImagePullNonExisting/asdfasdf (0.11s)

=== FAIL: amd64.integration.image TestImagePullNonExisting/library/asdfasdf (0.08s)
    pull_test.go:191: assertion failed: expected error to contain "pull access denied for asdfasdf, repository does not exist or may require 'docker login'", got "Error response from daemon: Get \"[https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest\](https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest/)": EOF"
        Error response from daemon: Get "https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest": EOF
    pull_test.go:192: assertion failed: error is Error response from daemon: Get "https://registry-1.docker.io/v2/library/asdfasdf/manifests/latest": EOF (errdefs.errSystem), not errdefs.IsNotFound
    --- FAIL: TestImagePullNonExisting/library/asdfasdf (0.08s)

=== FAIL: amd64.integration.image TestImagePullNonExisting (0.01s)

@thaJeztah thaJeztah merged commit 5e9c96e into moby:master Oct 17, 2024
@thaJeztah thaJeztah deleted the resize_uint branch October 17, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API impact/api kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants