filecoin-project / go-jsonrpc

Low Boilerplate JSON-RPC 2.0 library
Other
80 stars 91 forks source link

Some kinds of errors are returned as `%!s(PANIC=...nil pointer` #96

Open dirkmc opened 1 year ago

dirkmc commented 1 year ago

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 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

jacobheun commented 1 year ago

Believe this should be fixed in lotus, @dirkmc to confirm