Skip to content
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

fix(web3-errors): the undefined data in Eip838ExecutionError (#6905) #7147

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/web3-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ Documentation:

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

## [Unreleased]
## [Unreleased]

### Fixed

- Fixed the undefined data in `Eip838ExecutionError` constructor (#6905)
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
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
Loading