From d6a8c14d907cf8b90347444c0186b83a5db2e293 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 9 Oct 2023 20:20:32 -0400 Subject: [PATCH] Initial shortMessage support for errors (#4241). --- src.ts/utils/errors.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src.ts/utils/errors.ts b/src.ts/utils/errors.ts index ac56ad2a85..4d0b428f7f 100644 --- a/src.ts/utils/errors.ts +++ b/src.ts/utils/errors.ts @@ -22,7 +22,7 @@ import type { FetchRequest, FetchResponse } from "./fetch.js"; * An error may contain additional properties, but those must not * conflict with any impliciat properties. */ -export type ErrorInfo = Omit; +export type ErrorInfo = Omit & { shortMessage?: string }; function stringify(value: any): any { @@ -159,6 +159,12 @@ export interface EthersError extends Error { */ code: ErrorCode; + /** + * A short message describing the error, with minimal additional + * details. + */ + shortMessage: string; + /** * Additional info regarding the error that may be useful. * @@ -648,6 +654,8 @@ export function isCallException(error: any): error is CallExceptionError { * ethers version, %%code%% and all aditional properties, serialized. */ export function makeError>(message: string, code: K, info?: ErrorInfo): T { + let shortMessage = message; + { const details: Array = []; if (info) { @@ -655,6 +663,7 @@ export function makeError>(me throw new Error(`value will overwrite populated values: ${ stringify(info) }`); } for (const key in info) { + if (key === "shortMessage") { continue; } const value = (info[>key]); // try { details.push(key + "=" + stringify(value)); @@ -689,6 +698,10 @@ export function makeError>(me if (info) { Object.assign(error, info); } + if ((error).shortMessage == null) { + defineProperties(error, { shortMessage }); + } + return error; }