TypeChain icon indicating copy to clipboard operation
TypeChain copied to clipboard

[ethers-v5] Add initial support for custom errors

Open fredlacs opened this issue 2 years ago • 14 comments

This PR adds initial support for handling custom errors with Typechain. Still WIP but opening a draft PR to be able to get input from others on the approach (currently heavily inspired on https://github.com/dethcrypto/TypeChain/pull/457).

The idea here is to be able to handle errors in js/ts more cleanly when interacting with the chain. Although the functionality isn't here yet, it would be cool to be able to use these to have cleaner try catches when doing interactions with ethersjs

The current setup returns "undefined" for the error objects but is inspired in this. A couple alternatives on how this could work (ie could rely on ethers and upstream something there or could just have a separate entrypoint). That said, I think only the typed error object exports themselves are already useful, could also have a utility function to get the signature / encode expected values

fredlacs avatar May 01 '22 14:05 fredlacs

⚠️ No Changeset found

Latest commit: c29ed324ac15d313380cb1beb50a5ee31a69ec5a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar May 01 '22 14:05 changeset-bot[bot]

I think what we'd want here is to cast the ErrorFragment to a typed version of the error

fredlacs avatar May 02 '22 09:05 fredlacs

Related: https://github.com/dethcrypto/TypeChain/issues/667

krzkaczor avatar May 15 '22 13:05 krzkaczor

CI test(14.x) the test was failed Failing after 4m — test (14.x, ubuntu-latest

shashidhar771892 avatar Jul 06 '22 17:07 shashidhar771892

This looks reasonable. I am personally not a huge fan of custom errors and furthermore, ethersjs support is kinda minimal but the PR looks good!

@krzkaczor out of interest - what's the reasoning for not being a fan of custom errors? It feels like they provide a better opportunity to handle errors in clients, and can also reduce bytecode in deployed contracts. But i'm interested in any downsides too before using in a project

frontier159 avatar Jul 12 '22 00:07 frontier159

Error: Process completed with exit code 1. We can add the 56s in the CI / Test (14.x ubuntu-latest)

shashidhar771892 avatar Jul 13 '22 17:07 shashidhar771892

This would be an awesome improvement for typechain and the web3 developer experience overall IMO. Really looking forward to see this one merged. Would also be interested in arguments against it, @krzkaczor.

wottpal avatar Aug 22 '22 15:08 wottpal

Would love to see this merged, will unblock an issue with hardhat not having access to the errors in the interface provided by typechain and therefore not being able to use assertion helpers such as revertedWithCustomError in the chain helpers plugin they provide.

GeraldHost avatar Sep 06 '22 14:09 GeraldHost

@fredlacs @krzkaczor Is this pull request abandoned? Anything others can do to take it over the finish line?

KholdStare avatar Oct 10 '22 16:10 KholdStare

+1 for this feature. Can someone please re-trigger CI? The logs for last CI run are too old and disappeared.

tfalencar avatar Nov 16 '22 14:11 tfalencar

Having support for custom error in Typechain would be indeed very useful. Would be great if someone could re-trigger the CI :)

CJ42 avatar Mar 31 '23 17:03 CJ42

@fredlacs @krzkaczor Poking again, since it's been more than a year since this PR has been posted and issue https://github.com/dethcrypto/TypeChain/issues/667 has been raised.

KholdStare avatar Jun 19 '23 18:06 KholdStare

+1 for this feature.

emretepedev avatar Nov 04 '23 16:11 emretepedev

Any updates?

Alivers avatar Jan 09 '24 09:01 Alivers