* Get the [[ErrorFragment]] for %%key%%, which may be an error * selector, error name or error signature that belongs to the ABI. * * If %%values%% is provided, it will use the Typed API to handle * ambiguous cases where multiple errors match by name. * * If the %%
(key: string, values?: Array<any | Typed>)
| 699 | * the ABI, this will throw. |
| 700 | */ |
| 701 | getError(key: string, values?: Array<any | Typed>): null | ErrorFragment { |
| 702 | if (isHexString(key)) { |
| 703 | const selector = key.toLowerCase(); |
| 704 | |
| 705 | if (BuiltinErrors[selector]) { |
| 706 | return ErrorFragment.from(BuiltinErrors[selector].signature); |
| 707 | } |
| 708 | |
| 709 | for (const fragment of this.#errors.values()) { |
| 710 | if (selector === fragment.selector) { return fragment; } |
| 711 | } |
| 712 | |
| 713 | return null; |
| 714 | } |
| 715 | |
| 716 | // It is a bare name, look up the function (will return null if ambiguous) |
| 717 | if (key.indexOf("(") === -1) { |
| 718 | const matching: Array<ErrorFragment> = [ ]; |
| 719 | for (const [ name, fragment ] of this.#errors) { |
| 720 | if (name.split("("/* fix:) */)[0] === key) { matching.push(fragment); } |
| 721 | } |
| 722 | |
| 723 | if (matching.length === 0) { |
| 724 | if (key === "Error") { return ErrorFragment.from("error Error(string)"); } |
| 725 | if (key === "Panic") { return ErrorFragment.from("error Panic(uint256)"); } |
| 726 | return null; |
| 727 | } else if (matching.length > 1) { |
| 728 | const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); |
| 729 | assertArgument(false, `ambiguous error description (i.e. ${ matchStr })`, "name", key); |
| 730 | } |
| 731 | |
| 732 | return matching[0]; |
| 733 | } |
| 734 | |
| 735 | // Normalize the signature and lookup the function |
| 736 | key = ErrorFragment.from(key).format() |
| 737 | if (key === "Error(string)") { return ErrorFragment.from("error Error(string)"); } |
| 738 | if (key === "Panic(uint256)") { return ErrorFragment.from("error Panic(uint256)"); } |
| 739 | |
| 740 | const result = this.#errors.get(key); |
| 741 | if (result) { return result; } |
| 742 | |
| 743 | return null; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Iterate over all errors, calling %%callback%%, sorted by their name. |
no test coverage detected