Skip to content

Commit

Permalink
when -format-error option is used, format service reflection errors, …
Browse files Browse the repository at this point in the history
…too (#188)
  • Loading branch information
mkatychev committed Sep 30, 2020
1 parent 9846afc commit 9da71fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cmd/grpcurl/grpcurl.go
Expand Up @@ -695,7 +695,11 @@ func main() {

err = grpcurl.InvokeRPC(ctx, descSource, cc, symbol, append(addlHeaders, rpcHeaders...), h, rf.Next)
if err != nil {
fail(err, "Error invoking method %q", symbol)
if errStatus, ok := status.FromError(err); ok && *formatError {
h.Status = errStatus
} else {
fail(err, "Error invoking method %q", symbol)
}
}
reqSuffix := ""
respSuffix := ""
Expand Down
10 changes: 9 additions & 1 deletion invoke.go
Expand Up @@ -93,9 +93,17 @@ func InvokeRPC(ctx context.Context, source DescriptorSource, ch grpcdynamic.Chan
if svc == "" || mth == "" {
return fmt.Errorf("given method name %q is not in expected format: 'service/method' or 'service.method'", methodName)
}

dsc, err := source.FindSymbol(svc)
if err != nil {
if isNotFoundError(err) {
// return a gRPC status error if hasStatus is true
errStatus, hasStatus := status.FromError(err)
switch {
case hasStatus && isNotFoundError(err):
return status.Errorf(errStatus.Code(), "target server does not expose service %q: %s", svc, errStatus.Message())
case hasStatus:
return status.Errorf(errStatus.Code(), "failed to query for service descriptor %q: %s", svc, errStatus.Message())
case isNotFoundError(err):
return fmt.Errorf("target server does not expose service %q", svc)
}
return fmt.Errorf("failed to query for service descriptor %q: %v", svc, err)
Expand Down

0 comments on commit 9da71fb

Please sign in to comment.