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

Method getError

lib.esm/abi/interface.js:574–623  ·  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, values)

Source from the content-addressed store, hash-verified

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

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