-
Notifications
You must be signed in to change notification settings - Fork 112
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
Conversation
@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 Also, this came up in public Slack: https://bufbuild.slack.com/archives/CRZ680FUH/p1669918357272869 |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
Happy to cut a release as soon as this is merged, too! |
…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.
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 anErrorDetail
.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.