Skip to content

Commit

Permalink
fix(web3-errors): the undefined data in Eip838ExecutionError (#6905)
Browse files Browse the repository at this point in the history
* fix(web3-errors): handle the undefined data in Eip838ExecutionError constructor(#6433)

* doc: update changelog

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Muhammad Altabba <[email protected]>
Co-authored-by: Junaid <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2024
1 parent 89711ab commit 2b93c6a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ Documentation:

- Added `InvalidIntegerError` error for fromWei and toWei (#7052)

## [Unreleased]
## [Unreleased]
2 changes: 1 addition & 1 deletion packages/web3-errors/src/errors/contract_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Eip838ExecutionError extends Web3ContractError {
// error.data, error.data.data or error.data.originalError.data (https://github.com/web3/web3.js/issues/4454#issuecomment-1485953455)
if (typeof error.data === 'object') {
let originalError: { data: string };
if ('originalError' in error.data) {
if (error.data && 'originalError' in error.data) {
originalError = error.data.originalError;
} else {
// Ganache has no `originalError` sub-object unlike others
Expand Down
11 changes: 11 additions & 0 deletions packages/web3-errors/test/unit/__snapshots__/errors.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ exports[`errors Eip838ExecutionError should get the data from error.data.origina
}
`;

exports[`errors Eip838ExecutionError should return correctly when data is undefined 1`] = `
{
"cause": undefined,
"code": undefined,
"data": undefined,
"innerError": undefined,
"message": "Error",
"name": "Eip838ExecutionError",
}
`;

exports[`errors InvalidConnectionError should have valid json structure 1`] = `
{
"cause": undefined,
Expand Down
7 changes: 7 additions & 0 deletions packages/web3-errors/test/unit/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,13 @@ describe('errors', () => {
} as JsonRpcError<contractErrors.ProviderErrorData>).toJSON(),
).toMatchSnapshot();
});
it('should return correctly when data is undefined', () => {
expect(
new contractErrors.Eip838ExecutionError({
data: undefined,
} as JsonRpcError<contractErrors.ProviderErrorData>).toJSON(),
).toMatchSnapshot();
});
});

describe('ResponseError', () => {
Expand Down

0 comments on commit 2b93c6a

Please sign in to comment.