Add API to ABI coder for error recovery
See original GitHub issueWhen decoding events and functions for an ABI, various errors can occur, which are currently swallowed.
It would be nice if there was a way to gracefully recover from errors.
Errors to consider:
- Invalid UTF-8 string data (this is the most common); if a
- Insufficient data; this can occur when there is a mismatch in which event arguments are indexed or a function return type is incorrect
There is still some effort to figure out the best way to bubble these up to higher level libraries, but adding some of the functionality to the low-level coder should be fairly straight forward.
Possible Solutions:
- Allow an errorFunc function which will be called on errors to provide an alternate value
- Place a getter on the
Result
object that will throw when accessed, but with an error that contains the problematic data - Throw an error, with a recover function which will allow continuing decoding after the state has been corrected
I’ll be experimenting, and please feel free to make additional suggestions. 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
AbiCoder - Ethers.js
The AbiCoder is a collection of Coders which can be used to encode and decode the binary data formats used to interoperate between...
Read more >FIDL binary-compatibility (ABI) and source-compatibility (API ...
Often, a source-compatible rename is possible following the long process of adding a duplicate member with the desired name, switching all code ......
Read more >What is an application binary interface (ABI)? - Stack Overflow
The API consists of data types/structures, constants, functions, etc that you can use in your code to access the functionality of that external...
Read more >ABI Stability | Android Open Source Project
Application Binary Interface (ABI) stability is a prerequisite of framework-only updates because vendor modules may depend on the Vendor ...
Read more >28. ABI and API Deprecation - Documentation
rte_atomicNN_xxx: These APIs do not take memory order parameter. This does not allow for writing optimized code for all the CPU architectures supported...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve added initial support for option 2 above.
Basically, if you have a signature like
"event something(string bar, uint bar)"
, you willet back a Result object.Imagine that
bar
has overlong code units in it and decode theResult
object:So, non-exceptional cases can work like normal, and if someone cares about badly formatted data, they can detect it and correct it.
Thoughts?
@ricmoo I’m still facing this issue with attempts to return string to js.
And your approach with try-catch
ethers.utils.toUtf8String(error.value, ethers.utils.Utf8ErrorFuncs.ignore)
works! But, is there better solution? Thanks in advance!