-
Notifications
You must be signed in to change notification settings - Fork 510
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
Show additional error details when an rpc fails #379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,10 +136,25 @@ type Formatter func(proto.Message) (string, error) | |
func NewJSONFormatter(emitDefaults bool, resolver jsonpb.AnyResolver) Formatter { | ||
marshaler := jsonpb.Marshaler{ | ||
EmitDefaults: emitDefaults, | ||
Indent: " ", | ||
AnyResolver: resolver, | ||
} | ||
return marshaler.MarshalToString | ||
// Workaround for indentation issue in jsonpb with Any messages. | ||
// Bug was originally fixed in https://github.com/golang/protobuf/pull/834 | ||
// but later re-introduced before the module was deprecated and frozen. | ||
// If jsonpb is ever replaced with google.golang.org/protobuf/encoding/protojson | ||
// this workaround will no longer be needed. | ||
formatter := func(message proto.Message) (string, error) { | ||
output, err := marshaler.MarshalToString(message) | ||
if err != nil { | ||
return "", err | ||
} | ||
var buf bytes.Buffer | ||
if err := json.Indent(&buf, []byte(output), "", " "); err != nil { | ||
return "", err | ||
} | ||
return buf.String(), nil | ||
} | ||
return formatter | ||
} | ||
|
||
// NewTextFormatter returns a formatter that returns strings in the protobuf | ||
|
@@ -274,11 +289,11 @@ func (r *anyResolver) Resolve(typeUrl string) (proto.Message, error) { | |
if !ok { | ||
return nil, fmt.Errorf("unknown message: %s", typeUrl) | ||
} | ||
// populate any extensions for this message, too | ||
if exts, err := r.source.AllExtensionsForType(mname); err != nil { | ||
return nil, err | ||
} else if err := r.er.AddExtension(exts...); err != nil { | ||
return nil, err | ||
// populate any extensions for this message, too (if there are any) | ||
if exts, err := r.source.AllExtensionsForType(mname); err == nil { | ||
if err := r.er.AddExtension(exts...); err != nil { | ||
return nil, err | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's going on here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To give some extra context, we are trying to adopt the richer error model of grpc but grpcurl currently outputs the errors like this:
The problem with the current code here is that when using service reflection to resolve With the change in this PR, the
This new code should add extensions (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, that makes sense. Why not also ignore the error from |
||
} | ||
|
||
if r.mf == nil { | ||
|
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.
@jhump this seems reasonable to me, WDYT?
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.
Yep, this PR LGTM.