@@ -22,7 +22,7 @@ import type { FetchRequest, FetchResponse } from "./fetch.js";
22
22
* An error may contain additional properties, but those must not
23
23
* conflict with any impliciat properties.
24
24
*/
25
- export type ErrorInfo < T > = Omit < T , "code" | "name" | "message" > ;
25
+ export type ErrorInfo < T > = Omit < T , "code" | "name" | "message" | "shortMessage" > & { shortMessage ?: string } ;
26
26
27
27
28
28
function stringify ( value : any ) : any {
@@ -159,6 +159,12 @@ export interface EthersError<T extends ErrorCode = ErrorCode> extends Error {
159
159
*/
160
160
code : ErrorCode ;
161
161
162
+ /**
163
+ * A short message describing the error, with minimal additional
164
+ * details.
165
+ */
166
+ shortMessage : string ;
167
+
162
168
/**
163
169
* Additional info regarding the error that may be useful.
164
170
*
@@ -648,13 +654,16 @@ export function isCallException(error: any): error is CallExceptionError {
648
654
* ethers version, %%code%% and all aditional properties, serialized.
649
655
*/
650
656
export function makeError < K extends ErrorCode , T extends CodedEthersError < K > > ( message : string , code : K , info ?: ErrorInfo < T > ) : T {
657
+ let shortMessage = message ;
658
+
651
659
{
652
660
const details : Array < string > = [ ] ;
653
661
if ( info ) {
654
662
if ( "message" in info || "code" in info || "name" in info ) {
655
663
throw new Error ( `value will overwrite populated values: ${ stringify ( info ) } ` ) ;
656
664
}
657
665
for ( const key in info ) {
666
+ if ( key === "shortMessage" ) { continue ; }
658
667
const value = < any > ( info [ < keyof ErrorInfo < T > > key ] ) ;
659
668
// try {
660
669
details . push ( key + "=" + stringify ( value ) ) ;
@@ -689,6 +698,10 @@ export function makeError<K extends ErrorCode, T extends CodedEthersError<K>>(me
689
698
690
699
if ( info ) { Object . assign ( error , info ) ; }
691
700
701
+ if ( ( < any > error ) . shortMessage == null ) {
702
+ defineProperties < EthersError > ( < EthersError > error , { shortMessage } ) ;
703
+ }
704
+
692
705
return < T > error ;
693
706
}
694
707
0 commit comments