Commit 9659ac3
authored
fix: Ensure non-object data in RPC errors is deserialized correctly (#7638)
## Explanation
As-is the compatibility function `deserializeError` strips out valid
`data` if it isn't an object. Serialized values based on the
`JsonRpcError` class may have `data` that is any JSON value. This PR
fixes the issue by adding an additional case to the deserialization to
account for `data` being a non-object JSON value.
This for example ensures that "execution reverted" errors from the node
have the revert data properly populated.
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Ensures `deserializeError` retains non-object JSON `data` for RPC
errors while still merging `cause` appropriately.
>
> - Add `deserializeData` to merge object `data` with `cause` and pass
through primitive/JSON `data` using `isValidJson`
> - Update `deserializeError` to use `deserializeData`; import
`OptionalDataWithOptionalCause` and `isValidJson`
> - Extend tests to cover primitive `data` case and validated error
message behavior
> - Update `CHANGELOG.md` under Unreleased with the fix
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
6d843cb. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 8257977 commit 9659ac3
File tree
3 files changed
+44
-5
lines changed- packages/json-rpc-engine
- src/v2
3 files changed
+44
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
528 | 540 | | |
529 | 541 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | | - | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
135 | 161 | | |
136 | 162 | | |
137 | 163 | | |
| |||
177 | 203 | | |
178 | 204 | | |
179 | 205 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
| 206 | + | |
184 | 207 | | |
185 | 208 | | |
186 | 209 | | |
| |||
0 commit comments