* 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, values)
| 580 | * the ABI, this will throw. |
| 581 | */ |
| 582 | getError(key, values) { |
| 583 | if ((0, index_js_3.isHexString)(key)) { |
| 584 | const selector = key.toLowerCase(); |
| 585 | if (BuiltinErrors[selector]) { |
| 586 | return fragments_js_1.ErrorFragment.from(BuiltinErrors[selector].signature); |
| 587 | } |
| 588 | for (const fragment of this.#errors.values()) { |
| 589 | if (selector === fragment.selector) { |
| 590 | return fragment; |
| 591 | } |
| 592 | } |
| 593 | return null; |
| 594 | } |
| 595 | // It is a bare name, look up the function (will return null if ambiguous) |
| 596 | if (key.indexOf("(") === -1) { |
| 597 | const matching = []; |
| 598 | for (const [name, fragment] of this.#errors) { |
| 599 | if (name.split("(" /* fix:) */)[0] === key) { |
| 600 | matching.push(fragment); |
| 601 | } |
| 602 | } |
| 603 | if (matching.length === 0) { |
| 604 | if (key === "Error") { |
| 605 | return fragments_js_1.ErrorFragment.from("error Error(string)"); |
| 606 | } |
| 607 | if (key === "Panic") { |
| 608 | return fragments_js_1.ErrorFragment.from("error Panic(uint256)"); |
| 609 | } |
| 610 | return null; |
| 611 | } |
| 612 | else if (matching.length > 1) { |
| 613 | const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", "); |
| 614 | (0, index_js_3.assertArgument)(false, `ambiguous error description (i.e. ${matchStr})`, "name", key); |
| 615 | } |
| 616 | return matching[0]; |
| 617 | } |
| 618 | // Normalize the signature and lookup the function |
| 619 | key = fragments_js_1.ErrorFragment.from(key).format(); |
| 620 | if (key === "Error(string)") { |
| 621 | return fragments_js_1.ErrorFragment.from("error Error(string)"); |
| 622 | } |
| 623 | if (key === "Panic(uint256)") { |
| 624 | return fragments_js_1.ErrorFragment.from("error Panic(uint256)"); |
| 625 | } |
| 626 | const result = this.#errors.get(key); |
| 627 | if (result) { |
| 628 | return result; |
| 629 | } |
| 630 | return null; |
| 631 | } |
| 632 | /** |
| 633 | * Iterate over all errors, calling %%callback%%, sorted by their name. |
| 634 | */ |
no test coverage detected