MCPcopy Create free account
hub / github.com/ccxt/ccxt / getError

Method getError

js/src/static_dependencies/ethers/interface.js:485–534  ·  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

483 * the ABI, this will throw.
484 */
485 getError(key, values) {
486 if (isHexString(key)) {
487 const selector = key.toLowerCase();
488 if (BuiltinErrors[selector]) {
489 return ErrorFragment.from(BuiltinErrors[selector].signature);
490 }
491 for (const fragment of this.#errors.values()) {
492 if (selector === fragment.selector) {
493 return fragment;
494 }
495 }
496 return null;
497 }
498 // It is a bare name, look up the function (will return null if ambiguous)
499 if (key.indexOf("(") === -1) {
500 const matching = [];
501 for (const [name, fragment] of this.#errors) {
502 if (name.split("(" /* fix:) */)[0] === key) {
503 matching.push(fragment);
504 }
505 }
506 if (matching.length === 0) {
507 if (key === "Error") {
508 return ErrorFragment.from("error Error(string)");
509 }
510 if (key === "Panic") {
511 return ErrorFragment.from("error Panic(uint256)");
512 }
513 return null;
514 }
515 else if (matching.length > 1) {
516 const matchStr = matching.map((m) => JSON.stringify(m.format())).join(", ");
517 assertArgument(false, `ambiguous error description (i.e. ${matchStr})`, "name", key);
518 }
519 return matching[0];
520 }
521 // Normalize the signature and lookup the function
522 key = ErrorFragment.from(key).format();
523 if (key === "Error(string)") {
524 return ErrorFragment.from("error Error(string)");
525 }
526 if (key === "Panic(uint256)") {
527 return ErrorFragment.from("error Panic(uint256)");
528 }
529 const result = this.#errors.get(key);
530 if (result) {
531 return result;
532 }
533 return null;
534 }
535 /**
536 * Iterate over all errors, calling %%callback%%, sorted by their name.
537 */

Callers 3

decodeErrorResultMethod · 0.95
encodeErrorResultMethod · 0.95
parseErrorMethod · 0.95

Calls 9

isHexStringFunction · 0.90
assertArgumentFunction · 0.90
splitMethod · 0.80
pushMethod · 0.80
fromMethod · 0.45
valuesMethod · 0.45
mapMethod · 0.45
formatMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected