filecoin-project / filecoin-project/go-jsonrpc
Some kinds of errors are returned as `%!s(PANIC=...nil pointer`
- Dominant language
- Go
- Stars
- 100
- Forks
- 95
- PR merge metrics
- No merged PRs in 30d
Description
As described in https://github.com/filecoin-project/boost/issues/1193 when go-jsonrpc encounters some errors it turns them into `%!s(PANIC=...nil pointer`
lotus users have encountered this error message when making API calls that time out:
> ERROR: %!s(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)
The error message is printed out by [lotus cli helper](https://github.com/filecoin-project/lotus/blob/0c9f697bf611ad3a513d051a41e1288fa8859594/cli/helper.go#L52) when an error is returned from a CLI Action:
```
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
```
The format of the error message `%!s(PANIC=...nil pointer` indicates that fmt.Fprintf encountered a nil pointer when trying to call the `Error()` method on the golang `error` object that was passed to it. This is most likely because the `error` object wraps a nil error. An example golang Test that reproduces this behaviour:
```
type myerr struct {
err error
}
func (e *myerr) Error() string {
// if e.err is nil, this will panic
return e.err.Error()
}
func TestPrintErr(t *testing.T) {
fmt.Printf("%s\n", &myerr{})
}
=== RUN TestPrintErr
%!s(PANIC=Error method: runtime error: invalid memory address or nil pointer dereference)
--- PASS: TestPrintErr (0.00s)
```
It looks like the underlying implementation of go-jsonrpc is returning an error object that wraps a nil error. My best guess is that this bug was introduced in https://github.com/filecoin-project/go-jsonrpc/pull/72
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.