MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / getError

Method getError

src.ts/abi/interface.ts:702–745  ·  view source on GitHub ↗

* 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>)

Source from the content-addressed store, hash-verified

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

Callers 4

decodeErrorResultMethod · 0.95
encodeErrorResultMethod · 0.95
makeErrorMethod · 0.95
parseErrorMethod · 0.95

Calls 7

isHexStringFunction · 0.90
assertArgumentFunction · 0.90
fromMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45
mapMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected