@nxtedition/error
Advanced tools
+2
-0
@@ -19,2 +19,4 @@ export class AbortError extends Error { | ||
| errors?: NxtError[] | null | ||
| error?: NxtError[] | null | ||
| suppressed?: NxtError[] | null | ||
| } | ||
@@ -21,0 +23,0 @@ |
+66
-3
@@ -69,2 +69,26 @@ import objectHash from 'object-hash' | ||
| // SuppressedError (explicit resource management): rebuild a real instance, | ||
| // mirroring the AggregateError branch. Detect a live instance, a serialized | ||
| // one (`type`), or a name match — not a stray `suppressed` field on an | ||
| // unrelated object. `error`/`suppressed` are reconstructed into the instance | ||
| // itself, so drop them from the copied-over properties (they are enumerable in | ||
| // the serialized form; non-enumerable on a live instance). | ||
| if ( | ||
| typeof SuppressedError !== 'undefined' && | ||
| (error instanceof SuppressedError || | ||
| error.type === 'SuppressedError' || | ||
| error.name === 'SuppressedError') | ||
| ) { | ||
| delete properties.error | ||
| delete properties.suppressed | ||
| return Object.assign( | ||
| new SuppressedError(parseError(error.error), parseError(error.suppressed), message ?? ''), | ||
| { | ||
| ...properties, | ||
| cause: cause ? parseError(cause) : undefined, | ||
| data, | ||
| }, | ||
| ) | ||
| } | ||
| return Object.assign( | ||
@@ -194,2 +218,17 @@ Array.isArray(errors) | ||
| // SuppressedError (explicit resource management): `error` (the failure that | ||
| // superseded) and `suppressed` (the earlier, hidden failure) are | ||
| // non-enumerable own properties, so they never reach `...properties` and | ||
| // must be pulled out and serialized explicitly. Gate on the type so an | ||
| // unrelated `error`/`suppressed` field on a plain object is left untouched | ||
| // in `...properties`. | ||
| const primary = | ||
| type === 'SuppressedError' && error.error | ||
| ? _serializeError(error.error, { depth: depth + 1 }) | ||
| : undefined | ||
| const suppressed = | ||
| type === 'SuppressedError' && error.suppressed | ||
| ? _serializeError(error.suppressed, { depth: depth + 1 }) | ||
| : undefined | ||
| return [ | ||
@@ -222,2 +261,10 @@ JSON.parse( | ||
| errors: fp.isEmpty(errors) ? undefined : errors, | ||
| // Only emit these for a genuine SuppressedError; adding them | ||
| // unconditionally would clobber an unrelated object's own | ||
| // `error`/`suppressed` field (carried in `...properties`) with | ||
| // `undefined`. | ||
| ...(type === 'SuppressedError' && { | ||
| error: fp.isEmpty(primary) ? undefined : primary, | ||
| suppressed: fp.isEmpty(suppressed) ? undefined : suppressed, | ||
| }), | ||
| }, | ||
@@ -314,5 +361,10 @@ (k, v) => (typeof v === 'bigint' ? v.toString() : v), | ||
| ..._makeMessages( | ||
| [error.cause, error.error, error.errors, error.messages, error.status?.messages].filter( | ||
| Boolean, | ||
| ), | ||
| [ | ||
| error.cause, | ||
| error.error, | ||
| error.suppressed, | ||
| error.errors, | ||
| error.messages, | ||
| error.status?.messages, | ||
| ].filter(Boolean), | ||
| options, | ||
@@ -340,3 +392,14 @@ seen, | ||
| // SuppressedError: `error` is the failure that superseded and `suppressed` is | ||
| // the earlier, hidden one. parseError above rebuilds it as a real instance. | ||
| if (typeof SuppressedError !== 'undefined' && err instanceof SuppressedError) { | ||
| if (err.error) { | ||
| msg += `, error: ${makeErrorString(err.error)}` | ||
| } | ||
| if (err.suppressed) { | ||
| msg += `, suppressed: ${makeErrorString(err.suppressed)}` | ||
| } | ||
| } | ||
| return msg | ||
| } |
+2
-2
| { | ||
| "name": "@nxtedition/error", | ||
| "version": "1.1.38", | ||
| "version": "1.1.39", | ||
| "type": "module", | ||
@@ -28,3 +28,3 @@ "main": "lib/index.js", | ||
| }, | ||
| "gitHead": "1e4e772bc3128f962c6937c2c090a51d0602071b" | ||
| "gitHead": "44032308de159c06fc694c901a12c35a8bd628ea" | ||
| } |
14338
22.89%397
18.51%