Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to registry push errors #2981

Merged
merged 3 commits into from
Jul 27, 2022

Conversation

jonnystoten
Copy link
Member

@jonnystoten jonnystoten commented Jul 25, 2022

  • 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

@@ -301,7 +301,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src exporter.Source,
if e.push {
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
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
Member 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
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
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
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.

@@ -42,6 +42,12 @@ func ToGRPC(err error) error {
st = status.FromProto(pb)
}

if err.Error() != st.Message() {
Copy link
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
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