-
Notifications
You must be signed in to change notification settings - Fork 89
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #123 +/- ##
=========================================
Coverage ? 71.40%
=========================================
Files ? 12
Lines ? 1962
Branches ? 0
=========================================
Hits ? 1401
Misses ? 462
Partials ? 99
|
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 |
@aarshkshah1992 As per the @Stebalien comments : https://filecoinproject.slack.com/archives/CP50PPW2X/p1728439741305709?thread_ts=1727699414.185139&cid=CP50PPW2X We tried to add |
@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 ? |
@aarshkshah1992 so we hardcoded the |
errors.go
Outdated
} | ||
|
||
// DataError contains extra data to explain the error | ||
type DataError interface { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this interface{}
?
There was a problem hiding this comment.
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)
There was a problem hiding this 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 ?
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
Line 450 in c185272
callResult, err := doCall(req.Method, handler.handlerFunc, callParams) |
@rvagg Please can you 👁️ this ? |
some tests for this in here would be good |
This pull request includes a small change to the
handler.go
file. The change adds an optionalData
field to therespError
struct. This is done so as to implement changes mentioned in filecoin-project/lotus#10311handler.go
: AddedData
field to therespError
struct to include additional error information.