Skip to content
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

Error reporting on ParseUAST to avoid panic: runtime error #44

Closed
bzz opened this issue Jun 28, 2017 · 4 comments
Closed

Error reporting on ParseUAST to avoid panic: runtime error #44

bzz opened this issue Jun 28, 2017 · 4 comments
Labels

Comments

@bzz
Copy link
Contributor

bzz commented Jun 28, 2017

Right now resp, err := client.ParseUAST(context.TODO(), req) may fail with error beeing NOT nil but actual parsing has failed and there are resp.Errors and resp.status is fatal.

resp may be nil (i.e if server is not running) which is absolutely fine.

It seems like quite un-obvious behavior (at least for Golang) that may either be possible to fix or at least to documented everywhere, including https://doc.bblf.sh/user/server-grpc-example.html#full-source-of-the-example

Otherwise API users will :finnadie: on random NPE panics on further response.UAST manipulations (which do not propagate any error message).

Here is the example of client that works around current behavior, which boils down to

 resp, err := client.ParseUAST(context.TODO(), req)
 if err != nil {
 	fmt.Printf("Error - ParseUAST failed, reposne is nil, error:%v for %s\n", err, f.Name)
 } else if resp == nil {
 	fmt.Printf("No error, but - ParseUAST failed, response is nil\n")
 } else if (len(resp.Errors) != 0) || (resp.Status != protocol.Ok) {
 	fmt.Printf("No error, but - ParseUAST status:%s, error:%v for %s\n", resp.Status, resp.Errors, f.Name)
 }
@juanjux
Copy link
Contributor

juanjux commented Jun 28, 2017

I think there are two questions here.

  1. Should the response from a not running server be nil? I would like to avoid nil as much as possible, but if it's nil and err is not nil I don't see a big problem here (that behaviour is probably from the Go version of gRPC itself, but I'm not sure).

  2. ParseUAST should load err if resp.status != Ok? I think it should so the user shouldn't have to check it again on the err != nil path and should only have to check resp.Errors on the error path. This is probably the real bug.

@juanjux juanjux added the bug label Jun 28, 2017
@bzz
Copy link
Contributor Author

bzz commented Jun 28, 2017

@juanjux agree on both points, sorry for confusion. Updated the description above

@smola
Copy link
Member

smola commented Jun 28, 2017

Documentation fixed here: bblfsh/documentation#53

Note that the Babelfish protocol defines its own error handling (status and errors) for parsing. This is then wrapped in gRPC which generates its own error handling (as second return value: err). There's not much we can do here unless we want to offer a more high level wrapper on the client side.

@smola smola closed this as completed Jun 28, 2017
@bzz
Copy link
Contributor Author

bzz commented Jun 28, 2017

Sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants