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 API to make it easier to work with ErrorDetail if you have/want an Any #409

Merged
merged 5 commits into from
Dec 1, 2022
Merged

add API to make it easier to work with ErrorDetail if you have/want an Any #409

merged 5 commits into from
Dec 1, 2022

Conversation

jhump
Copy link
Member

@jhump jhump commented Dec 1, 2022

If your code already has an instance of Any, it's a pain (and not even guaranteed to be possible at runtime!) to unmarshal the message therein only to re-wrap it in order to put it in an ErrorDetail.

Similarly, if you can't unmarshal the contained type, it may be useful to access the Any envelope.

This adds two new APIs for just this.

@jhump
Copy link
Member Author

jhump commented Dec 1, 2022

@akshayjshah, what do you think?

I actually encountered this when I was trying to formulate adapters from gRPC generated interfaces to Connect. In those cases, I needed to convert a gRPC *status.Error into a *connect.Error, and vice versa. Without methods like this, there's no easier way to do that.

Also, this came up in public Slack: https://bufbuild.slack.com/archives/CRZ680FUH/p1669918357272869

Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

LGTM with the smaller surface area! Some docs suggestions, but no need for more review.

error.go Outdated
@@ -44,8 +44,13 @@ type ErrorDetail struct {
wireJSON string // preserve human-readable JSON
}

// NewErrorDetail constructs a new error detail.
// NewErrorDetail constructs a new error detail. This returns an error
// if msg cannot be marshalled into an Any message.
Copy link
Member

Choose a reason for hiding this comment

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

A surprising number of people aren't familiar with the WKTs. Can we turn Any into a newfangled GoDoc link to the docs for *anypb.Any? I think [google.golang.org/protobuf/types/known/anypb.Any] works.

Also, can we document that this doesn't re-wrap if you pass an Any?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I've used simple type links, so I changed Any to [anypb.Any].

An alternative would be to write it as [Any] and then add a footnote:

[Any]: https://pkg.go.dev/google.golang.org/protobuf/types/known/anypb#Any

Would you prefer that alternative? (reference)

@akshayjshah
Copy link
Member

Happy to cut a release as soon as this is merged, too!

@akshayjshah akshayjshah merged commit c16c8c9 into connectrpc:main Dec 1, 2022
akshayjshah pushed a commit that referenced this pull request Jul 26, 2023
…n Any (#409)

If your code already has an instance of `Any`, it's a pain (and not even
guaranteed to be possible at runtime!) to unmarshal the message therein
only to re-wrap it in order to put it in an `ErrorDetail`.

Similarly, if you can't unmarshal the contained type, it may be useful
to access the `Any` envelope.

This adds two new APIs for just this.
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.

2 participants