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

sendTransaction and sendSignedTransaction Error Refactors #5854

Merged
merged 69 commits into from
Mar 9, 2023

Conversation

spacesailor24
Copy link
Contributor

@spacesailor24 spacesailor24 commented Feb 22, 2023

Added

web3-errors

web3-eth

Changed

web3-errors

web3-eth

  • sendTransaction and sendSignedTransaction now errors with (and error event emits) the following possible errors: TransactionRevertedWithoutReasonError, TransactionRevertInstructionError, TransactionRevertWithCustomError, InvalidResponseError, or ContractExecutionError (sendTransaction and sendSignedTransaction Error Refactors #5854)

@spacesailor24 spacesailor24 added the 4.x 4.0 related label Feb 22, 2023
@spacesailor24 spacesailor24 self-assigned this Feb 22, 2023
@@ -55,16 +65,24 @@ export class ResponseError<ErrorType = unknown> extends BaseWeb3Error {
? response.map(r => r.error?.data as ErrorType)
: response?.error?.data;
}

this.request = request;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added request to the error object as I wanted to add sent transaction details to failed transaction errors to give the user more context (e.g. the sending account when the error Unknown account or Insufficient funds is thrown) on what exactly was sent to provider

Comment on lines 1081 to 1088
if (web3Context.handleRevert) {
// eslint-disable-next-line no-use-before-define
await getRevertReason(
web3Context,
transactionFormatted as TransactionCall,
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of addressing #5839, the revert reason is retrieved after the transaction has been processed by the network and when transactionReceipt.status === BigInt(0)

Comment on lines -1181 to -1187
promiEvent.emit(
'error',
new TransactionError(
'Transaction failed',
transactionReceiptFormatted,
),
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the cause of #5837

Comment on lines -1209 to -1211
if (error instanceof ContractExecutionError) {
promiEvent.emit('contractExecutionError', error);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a reason to have an contractExecutionError event when we already have a generic error event that every other error uses (@nikoulai please let me know if there was a specific reason for it since you added it in #5659)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that it's being using in web3-eth-contract

Copy link
Contributor Author

@spacesailor24 spacesailor24 Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

web3-eth-contract was updated to check for error instanceof ContractExecutionError instead of relying on an emission of contractExecutionError event

@@ -25,6 +25,45 @@ import { DataFormat, DEFAULT_RETURN_FORMAT } from 'web3-utils';
import { call } from '../rpc_method_wrappers';
import { RevertReason, RevertReasonWithCustomError } from '../types';

export const parseTransactionError = (error: unknown, contractAbi?: ContractAbi) => {
Copy link
Contributor Author

@spacesailor24 spacesailor24 Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to it's own function so it could make getRevertReason more concise and because the new util method getTransactionError uses it

@github-actions
Copy link

github-actions bot commented Feb 24, 2023

Bundle Stats

Hey there, this message comes from a github action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Asset Old size New size Diff Diff %
Total 1.18 MB 1.06 MB -116 KB -9.61%
View detailed bundle breakdown

Added

Asset Old size New size Diff Diff %
../lib/eth.exports.d.ts.map 0 358 bytes 358 bytes -
../lib/eth.exports.d.ts 0 321 bytes 321 bytes -
../lib/providers.exports.d.ts.map 0 292 bytes 292 bytes -
../lib/providers.exports.d.ts 0 238 bytes 238 bytes -

Removed

No assets were removed

Bigger

Asset Old size New size Diff Diff %
../lib/index.d.ts 77 bytes 899 bytes 822 bytes 1067.53%
../lib/index.d.ts.map 155 bytes 919 bytes 764 bytes 492.90%

Smaller

Asset Old size New size Diff Diff %
web3.min.js 1.17 MB 1.05 MB -118 KB -9.88%
../lib/types.d.ts 1.92 KB 1.68 KB -253 bytes -12.84%
../lib/types.d.ts.map 1.75 KB 1.51 KB -241 bytes -13.46%

Unchanged

Asset Old size New size Diff Diff %
../lib/accounts.d.ts 3.42 KB 3.42 KB 0 0.00%
../lib/abi.d.ts 1020 bytes 999 bytes -18 bytes -1.77%
../lib/web3.d.ts 842 bytes 842 bytes 0 0.00%
../lib/web3.d.ts.map 693 bytes 694 bytes 1 bytes 0.14%
../lib/accounts.d.ts.map 528 bytes 528 bytes 0 0.00%
../lib/version.d.ts.map 140 bytes 140 bytes 0 0.00%
../lib/abi.d.ts.map 124 bytes 124 bytes 0 0.00%
../lib/version.d.ts 97 bytes 97 bytes 0 0.00%

@github-actions github-actions bot temporarily deployed to Preview: (wyatt/4.x/5840-requstmanger-return-errors) February 24, 2023 02:30 Inactive
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 24, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: c216751
Status: ✅  Deploy successful!
Preview URL: https://4e10d048.web3-js-docs.pages.dev
Branch Preview URL: https://wyatt-4-x-5840-requstmanger-.web3-js-docs.pages.dev

View logs

@github-actions github-actions bot temporarily deployed to Preview: (wyatt/4.x/5840-requstmanger-return-errors) February 24, 2023 02:31 Inactive
@github-actions github-actions bot temporarily deployed to Preview: (wyatt/4.x/5840-requstmanger-return-errors) February 24, 2023 03:20 Inactive
@github-actions github-actions bot temporarily deployed to Preview: (wyatt/4.x/5840-requstmanger-return-errors) February 24, 2023 04:17 Inactive
spacesailor24 and others added 22 commits March 9, 2023 09:20
…scendants (#5891)

* rename `_providerOptions` to `_socketOptions`

* pass `_socketOptions` from IpcProvider constructor to the underlying connection

* move a comment to its correct position at `SocketProvider`

* expose the getter of `SocketConnection` from `SocketProvider`.

* update CHANGELOG.md files

* add extremely simple unit test for SocketProvider
* version fix

* use geth binary

* try 1.11.2
* use `v1` instead of short Sha for cloudflare/pages-action
@spacesailor24 spacesailor24 force-pushed the wyatt/4.x/5840-requstmanger-return-errors branch from 679d2fa to 2662eaf Compare March 9, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants