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

feat: add 'Data' field to 'respError' struct #123

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

virajbhartiya
Copy link
Member

This pull request includes a small change to the handler.go file. The change adds an optional Data field to the respError struct. This is done so as to implement changes mentioned in filecoin-project/lotus#10311

  • handler.go: Added Data field to the respError struct to include additional error information.

@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 71.05263% with 22 lines in your changes missing coverage. Please review.

Please upload report for BASE (master@c185272). Learn more about missing BASE report.

Files with missing lines Patch % Lines
handler.go 23.07% 19 Missing and 1 partial ⚠️
websocket.go 33.33% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #123   +/-   ##
=========================================
  Coverage          ?   71.40%           
=========================================
  Files             ?       12           
  Lines             ?     1962           
  Branches          ?        0           
=========================================
  Hits              ?     1401           
  Misses            ?      462           
  Partials          ?       99           
Files with missing lines Coverage Δ
client.go 79.67% <ø> (ø)
errors.go 65.21% <ø> (ø)
response.go 100.00% <100.00%> (ø)
server.go 75.75% <100.00%> (ø)
websocket.go 74.41% <33.33%> (ø)
handler.go 69.34% <23.07%> (ø)

@aarshkshah1992
Copy link

I think we will need more changes here for the library to determine if the error has data and to read it from the error but we can worry about it when we get blocked by it. We'll find out more when we do the Lotus work. Update Lotus to use this go-jsonrpc commit locally while you are working on the Lotus PR.

@akaladarshi
Copy link

@aarshkshah1992 As per the @Stebalien comments : https://filecoinproject.slack.com/archives/CP50PPW2X/p1728439741305709?thread_ts=1727699414.185139&cid=CP50PPW2X

We tried to add json.RawMessage, but I was getting json body invalid in response, so I went back to using interface,
I personally haven't gone into the detail why it was happening but if you have any thought about this let us know.

@aarshkshah1992
Copy link

@akaladarshi Before I review this -> can you guys post a snippet of the errors you see for contract reverts when calling via JSON RPC on a Calibnet node ?

@akaladarshi
Copy link

akaladarshi commented Oct 9, 2024

@akaladarshi Before I review this -> can you guys post a snippet of the errors you see for contract reverts when calling via JSON RPC on a Calibnet node ?

Screenshot 2024-10-09 at 8 54 25 PM

@aarshkshah1992 so we hardcoded the message ourselves but the data is fetched from the error returned after applying the message.

@akaladarshi
Copy link

and for same function call ethereum returns this
Screenshot 2024-10-09 at 9 00 44 PM

errors.go Outdated
}

// DataError contains extra data to explain the error
type DataError interface {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrorWithData

errors.go Outdated
@@ -58,3 +58,15 @@ type marshalable interface {
json.Marshaler
json.Unmarshaler
}

// Error wraps RPC errors, which contain an error code in addition to the message.
type Error interface {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this interface ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added so we can have custom error codes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need custom error codes ? Can you write a bit explaining what made you add this ? Was it something you saw during your testing ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this needs a better name. This can be ErrorWithCode and the below can be ErrorWithData

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarshkshah1992 I think this will give more idea towards the error codes: filecoin-project/lotus#12553

handler.go Outdated
@@ -69,6 +70,7 @@ type respError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Meta json.RawMessage `json:"meta,omitempty"`
Data interface{} `json:"data,omitempty"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this interface{} ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarshkshah1992 I posted a comment above in current PR regarding this: #123 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this just a string ? Why does it have to be json.RawMessage or interface{}

@rvagg -> Any thoughts ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.jsonrpc.org/specification#error_object

A Primitive or Structured value that contains additional information about the error.

🤷 interface{} would seem more accurate, as long as it's serialisable

handler.go Outdated
}
}

var err2 Error
if errors.As(err, &err2) {
out.Code = ErrorCode(err2.ErrorCode())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we setting the code here again ? Don't we already have it on line 355 above ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarshkshah1992
So in line 355 we are setting the registered error codes, but here we are setting the custom error code.

I think we can directly register the code for ErrWithExecutionReverted, but then we need to finalise on which code to use, as error code 3 is already registered with the ActorNotFound

handler.go Outdated
@@ -504,10 +524,17 @@ func (s *handler) handle(ctx context.Context, req request, w func(func(io.Writer

log.Warnf("failed to setup channel in RPC call to '%s': %+v", req.Method, err)
stats.Record(ctx, metrics.RPCResponseError.M(1))
resp.Error = &respError{
respErr := &respError{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to do the same thing in the rpcError function in server.go ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not as rpcErr is only used for RPC processing errors and not errors returned by the invocation of the function.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this because rpcError function is returning errors specific to RPCs (method not found etc), but the actual execution error is inside the handle function after doCall here:

callResult, err := doCall(req.Method, handler.handlerFunc, callParams)

@aarshkshah1992
Copy link

@rvagg Please can you 👁️ this ?

@rvagg
Copy link
Member

rvagg commented Oct 16, 2024

some tests for this in here would be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ⌨️ In Progress
Development

Successfully merging this pull request may close these issues.

5 participants