Skip to content

Commit

Permalink
fix(web3-errors): handle the undefined data in Eip838ExecutionError c…
Browse files Browse the repository at this point in the history
…onstructor(web3#6433)
  • Loading branch information
Alfxjx committed Mar 16, 2024
1 parent 16a2c27 commit 544902a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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 544902a

Please sign in to comment.