@@ -3,7 +3,7 @@ import handleCliError, {
33 validateOptions ,
44 type Options as HandleCliErrorOptions ,
55} from 'handle-cli-error'
6- import type { Info , Plugin } from 'modern-errors'
6+ import type { ErrorInstance , Info , Plugin } from 'modern-errors'
77
88/**
99 * Options of `modern-errors-cli`
@@ -50,7 +50,13 @@ const getOptions = (options: Options = {}) => {
5050 * ```
5151 */
5252const exit = ( { error, options } : Info < Options > [ 'instanceMethods' ] ) => {
53- handleCliError ( error , { ...options , custom : 'pretty' } )
53+ removePretty ( error )
54+
55+ try {
56+ handleCliError ( error , { ...options , custom : 'pretty' } )
57+ } finally {
58+ restorePretty ( error )
59+ }
5460}
5561
5662// Uses `.pretty()` to avoid conflict with `modern-errors-beautiful`.
@@ -60,20 +66,28 @@ const pretty = ({
6066 // eslint-disable-next-line @typescript-eslint/no-unused-vars
6167 options : { exitCode, silent, timeout, log, ...beautifulErrorOptions } ,
6268} : Info < Options > [ 'instanceMethods' ] ) => {
69+ removePretty ( error )
70+
71+ try {
72+ return beautifulError ( error , beautifulErrorOptions )
73+ } finally {
74+ restorePretty ( error )
75+ }
76+ }
77+
78+ const removePretty = ( error : ErrorInstance ) => {
6379 // eslint-disable-next-line fp/no-mutating-methods
6480 Object . defineProperty ( error , 'pretty' , {
6581 value : undefined ,
6682 enumerable : false ,
6783 writable : true ,
6884 configurable : true ,
6985 } )
86+ }
7087
71- try {
72- return beautifulError ( error , beautifulErrorOptions )
73- } finally {
74- // eslint-disable-next-line fp/no-delete
75- delete ( error as Error & { pretty ?: undefined } ) . pretty
76- }
88+ const restorePretty = ( error : ErrorInstance & { pretty ?: undefined } ) => {
89+ // eslint-disable-next-line fp/no-delete
90+ delete error . pretty
7791}
7892
7993/**
0 commit comments