@@ -2,21 +2,35 @@ import { inspect } from 'util'
22
33import { getMessage } from './message.js'
44import { printError } from './print.js'
5- import { getEventProps } from './props.js'
65import { getStack } from './stack.js'
76
87const { custom } = inspect
98
109// Retrieve `error` which sums up all information that can be gathered about
1110// the event.
1211export const getError = function ( { name, event } ) {
13- const { stack, ...staticProps } = getEventProps ( event )
1412 const message = getMessage ( { event, name } )
15- const stackA = getStack ( stack )
13+ const mainValue = getMainValue ( event )
14+ const staticProps = getEventProps ( mainValue )
15+ const stackA = getStack ( mainValue )
1616 const error = buildError ( { name, message, stack : stackA , staticProps } )
1717 return { error, stack : stackA }
1818}
1919
20+ // Retrieve main thrown value, which is most likely an `Error` instance
21+ const getMainValue = function ( { value, nextValue : mainValue = value } ) {
22+ return mainValue
23+ }
24+
25+ // If event is an error, retrieve static properties except `name` and `message`
26+ const getEventProps = function ( mainValue ) {
27+ if ( mainValue instanceof Error ) {
28+ return { ...mainValue }
29+ }
30+
31+ return { }
32+ }
33+
2034const buildError = function ( { name, message, stack, staticProps } ) {
2135 const error = new Error ( message )
2236 // eslint-disable-next-line fp/no-mutating-assign
0 commit comments