Skip to content

Add context to registry push errors - #2981

Merged
tonistiigi merged 3 commits into
moby:masterfrom
jonnystoten:better-push-error
Jul 27, 2022
Merged

Add context to registry push errors#2981
tonistiigi merged 3 commits into
moby:masterfrom
jonnystoten:better-push-error

Conversation

@jonnystoten

@jonnystoten jonnystoten commented Jul 25, 2022

Copy link
Copy Markdown
Contributor
  • Extract containerimage export push function
  • Wrap push error with target name
  • Use original error's message for gRPC error

Fixes #2019.

Registry push error from buildx before this change:

 => ERROR exporting to image                                                                                                                                                                                1.1s
 => => exporting layers                                                                                                                                                                                     0.0s
 => => exporting manifest sha256:d2cfb97f444d76147c440c6b86b333d388735b75b3644718cb5a4e0ad4e23762                                                                                                           0.0s
 => => exporting config sha256:35d75deef09995f6980a80122699b12059b946997dc2acf0d121970cd662c103                                                                                                             0.0s
 => => pushing layers                                                                                                                                                                                       1.1s
------
 > exporting to image:
------
ERROR: failed to solve: server message: insufficient_scope: authorization failed

and after:

 => ERROR exporting to image                                                                                                                                                                                1.4s
 => => exporting layers                                                                                                                                                                                     0.0s
 => => exporting manifest sha256:d2cfb97f444d76147c440c6b86b333d388735b75b3644718cb5a4e0ad4e23762                                                                                                           0.0s
 => => exporting config sha256:35d75deef09995f6980a80122699b12059b946997dc2acf0d121970cd662c103                                                                                                             0.0s
 => => pushing layers                                                                                                                                                                                       1.4s
------
 > exporting to image:
------
ERROR: failed to solve: failed to push docker.io/username/image: server message: insufficient_scope: authorization failed

Comment thread exporter/containerimage/export.go Outdated
err := e.pushImage(ctx, src, sessionID, targetName, desc.Digest)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to push %v: %w", targetName, err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't allow fmt.Errorf in build repos because they lose stacktraces. Use pkg/errors.Wrap

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does it lose stack traces even with %w?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes. Stdlib errors does not capture a stacktrace.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, makes sense. I misunderstood your comment and thought you meant it would remove existing stack traces from the error chain.

st = status.FromProto(pb)
}

if err.Error() != st.Message() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a comment in here that "If grpc error was wrapped with additional message then set full message to grpc error".

Otherwise it is quite tricky to understand why this code is in here.

Signed-off-by: Jonny Stoten <jonny.stoten@docker.com>
Signed-off-by: Jonny Stoten <jonny.stoten@docker.com>
Signed-off-by: Jonny Stoten <jonny.stoten@docker.com>
@tonistiigi
tonistiigi merged commit 2973bb9 into moby:master Jul 27, 2022
@jonnystoten
jonnystoten deleted the better-push-error branch July 27, 2022 08:54
emmanuelguerin pushed a commit to emmanuelguerin/buildkit that referenced this pull request Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

registry errors lack detail

3 participants