Skip to content

Commit

Permalink
[FIX] Fix unchecked rpc.DataError cast causing panics in archiver logs (
Browse files Browse the repository at this point in the history
#1845)

An error for the archiver is showing up in the logs as

```
panic: interface conversion: interface {} is nil, not string
```

And I think this is the issue.
  • Loading branch information
clemire authored Dec 17, 2024
1 parent cb59a57 commit 073e0c8
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions core/node/base/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,21 +267,23 @@ func AsRiverError(err error, defaultCode ...protocol.Err) *RiverErrorImpl {
if de, ok := err.(rpc.DataError); ok {
var tags []RiverErrorTag
if de.ErrorData() != nil {
hexStr := de.ErrorData().(string)
hexStr = strings.TrimPrefix(hexStr, "0x")
revert, e := hex.DecodeString(hexStr)
if e == nil {
reason, e := abi.UnpackRevert(revert)
hexStr, ok := de.ErrorData().(string)
if ok {
hexStr = strings.TrimPrefix(hexStr, "0x")
revert, e := hex.DecodeString(hexStr)
if e == nil {
tags = []RiverErrorTag{{"revert_reason", reason}}
if reason == ContractErrorStreamNotFound {
code = protocol.Err_NOT_FOUND
} else if reason == ContractErrorNodeNotFound {
code = protocol.Err_UNKNOWN_NODE
} else if reason == ContractErrorAlreadyExists {
code = protocol.Err_ALREADY_EXISTS
} else if reason == ContractErrorOutOfBounds {
code = protocol.Err_INVALID_ARGUMENT
reason, e := abi.UnpackRevert(revert)
if e == nil {
tags = []RiverErrorTag{{"revert_reason", reason}}
if reason == ContractErrorStreamNotFound {
code = protocol.Err_NOT_FOUND
} else if reason == ContractErrorNodeNotFound {
code = protocol.Err_UNKNOWN_NODE
} else if reason == ContractErrorAlreadyExists {
code = protocol.Err_ALREADY_EXISTS
} else if reason == ContractErrorOutOfBounds {
code = protocol.Err_INVALID_ARGUMENT
}
}
}
}
Expand Down

0 comments on commit 073e0c8

Please sign in to comment.