Comments (4)
This is good catch. I planned to fix this before releasing but forgot to do
that. will send out a PR to fix this.
On Tue, Mar 3, 2015 at 2:08 PM, Tv [email protected] wrote:
$ cd $GOPATH/src/github.com/grpc/grpc-common/go
$ git diffdiff --git i/go/greeter_server/main.go w/go/greeter_server/main.goindex c7fa06a..c7682cb 100644--- i/go/greeter_server/main.go+++ w/go/greeter_server/main.go@@ -40,6 +40,7 @@ import ( pb "github.com/grpc/grpc-common/go/helloworld" "golang.org/x/net/context" "google.golang.org/grpc"+ "google.golang.org/grpc/codes" )
const (@@ -51,7 +52,7 @@ type server struct{}
// SayHello implements helloworld.GreeterServer func (s _server) SayHello(ctx context.Context, in *pb.HelloRequest) (_pb.HelloReply, error) {- return &pb.HelloReply{Message: "Hello " + in.Name}, nil+ return nil, grpc.Errorf(codes.DataLoss, "too grumpy to greet") }
func main() {
$ go run greeter_server/main.go &[1] 12775
$ go run greeter_client/main.go 2015/03/03 13:53:30 could not greet: rpc error: code = 2 desc = "rpc error: code = 15 desc = "too grumpy to greet""exit status 1I expected to see code=15, now I see code=2 wrapping a code=15.
My reading of the source (
https://github.com/grpc/grpc-go/blob/master/server.go#L246 ,
https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L227 ) says
convertCode should have if err, ok := err.(rpcError); ok { return
err.code }.That still leaves the textual double-wrapping; it seems that should not be
done on the server-side for rpcError, just send rpcError.desc if the
error is a grpcError.Also, could there be a little less textual wrapping? And could those codes
get a go stringer on them? Here's what might be ideal:could not greet: rpc error: DataLoss: too grumpy to greet
and only start doing quoting if the message is "hostile", as in contains
\n etc. That would require defining a safe set of runes.—
Reply to this email directly or view it on GitHub
#92.
from grpc-go.
okay, this is actually a misuse. We do not expect users to set error code in their service handler implementation. They should simply return nil, fmt.Errorf("too grumpy to greet"). We should have had an example for this.
But I probably should handle this case as well to obey whatever error code the server application sets if it does. Let me think ...
from grpc-go.
If what you're saying is going to hold, then it sounds like grpc.Errorf
should not be exported.
However, consider the implications: if Codes are only supposed to be created by convertCode
/toRPCErr
, that means the only way to return a codes.AlreadyExists
from something that is not an OS-level file system operation or such is to use platform-dependent erorrs like syscall.EEXIST
(attempt to make os.IsExist(err)==true
). At that point, it seems like the Code mechanism is unusable, and people would be better off with enum error types in their response messages. And in that case, why are there so many Codes?
And yes, more clarity into intents of the mechanism is most welcome.
from grpc-go.
On Wed, Mar 4, 2015 at 6:41 PM, Tv [email protected] wrote:
If what you're saying is going to hold, then it sounds like grpc.Errorf
should not be exported.However, consider the implications: if Codes are only supposed to be
created by convertCode/toRPCErr, that means the only way to return a
codes.AlreadyExists from something that is not an OS-level file system
operation or such is to use platform-dependent erorrs like syscall.EEXIST
(attempt to make os.IsExist(err)==true). At that point, it seems like the
Code mechanism is unusable, and people would be better off with enum error
types in their response messages. And in that case, why are there so many
Codes?And yes, more clarity into intents of the mechanism is most welcome.
Yup, I will have a pull request to fix this shortly.
—
Reply to this email directly or view it on GitHub
#92 (comment).
from grpc-go.
Related Issues (20)
- bufnet not supported by NewClient() ? HOT 5
- Please release upgrade /cmd/protoc-gen-go-grpc /go.mod to security fixed protobuf v1.33.0 HOT 2
- Confusing for NewClient in 1.63 HOT 4
- Deprecate WithBlock and WithReturnConnectionError HOT 3
- gRPC casing looks really ugly [Serious] HOT 2
- resolver.Address's BalancerAttributes update will not reflect in Balancer HOT 3
- How to modify the returned metadata HOT 3
- In picker logic(picker_wrapper.go), clearly understand the real reason for failures after a context.Error(timeout) HOT 2
- rpc error: code = Internal desc = header key "myheader" contains value with non-printable ASCII characters HOT 1
- Move pick_first to separate package
- run staticcheck for all modules
- header key "XXX" contains value with non-printable ASCII characters HOT 1
- Service reflection can not handle directory paths with imported proto files HOT 1
- Delete grpclog's Debugf function HOT 3
- feature: `protoc-gen-go-grpc` to create test client / `bufconn` constructors HOT 2
- Flaky test: TestClientSendsAGoAway HOT 8
- Catching grpc connection configuration errors at startup HOT 2
- CloseSend immediately after Send
- Minor 'invalid code' error output suggestion
- advancedtls package does not set VerifiedChains in TLSInfo.State HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-go.