propagate reflection status error

This commit is contained in:
Mikhail Katychev 2020-09-29 17:35:17 -05:00
parent 9846afccbc
commit 1e796ea75f
No known key found for this signature in database
GPG Key ID: 9E8549CD2CEB5E59
2 changed files with 10 additions and 1 deletions

View File

@ -695,7 +695,11 @@ func main() {
err = grpcurl.InvokeRPC(ctx, descSource, cc, symbol, append(addlHeaders, rpcHeaders...), h, rf.Next) err = grpcurl.InvokeRPC(ctx, descSource, cc, symbol, append(addlHeaders, rpcHeaders...), h, rf.Next)
if err != nil { if err != nil {
fail(err, "Error invoking method %q", symbol) if errStatus, ok := status.FromError(err); ok {
h.Status = errStatus
} else {
fail(err, "Error invoking method %q", symbol)
}
} }
reqSuffix := "" reqSuffix := ""
respSuffix := "" respSuffix := ""

View File

@ -93,11 +93,16 @@ func InvokeRPC(ctx context.Context, source DescriptorSource, ch grpcdynamic.Chan
if svc == "" || mth == "" { if svc == "" || mth == "" {
return fmt.Errorf("given method name %q is not in expected format: 'service/method' or 'service.method'", methodName) return fmt.Errorf("given method name %q is not in expected format: 'service/method' or 'service.method'", methodName)
} }
dsc, err := source.FindSymbol(svc) dsc, err := source.FindSymbol(svc)
if err != nil { if err != nil {
if isNotFoundError(err) { if isNotFoundError(err) {
return fmt.Errorf("target server does not expose service %q", svc) return fmt.Errorf("target server does not expose service %q", svc)
} }
// return the error unstringified if it is a gRPC status.Status error
if _, ok := status.FromError(err); ok {
return err
}
return fmt.Errorf("failed to query for service descriptor %q: %v", svc, err) return fmt.Errorf("failed to query for service descriptor %q: %v", svc, err)
} }
sd, ok := dsc.(*desc.ServiceDescriptor) sd, ok := dsc.(*desc.ServiceDescriptor)