@@ -27,7 +27,6 @@ to/from plain objects.
2727 ` process.send() ` )
2828- Keeps [ error classes] ( #baseerrorparseerrorobject )
2929- Preserves errors' [ additional properties] ( #additional-error-properties )
30- - Can keep ` custom ` [ constructor's arguments] ( #constructors-arguments )
3130- Works [ recursively] ( #aggregate-errors ) with
3231 [ ` AggregateError ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError )
3332- Safe: this never throws
@@ -100,14 +99,16 @@ etc.). This is
10099[ automatically called] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior )
101100by ` JSON.stringify() ` . All error properties
102101[ are kept] ( https://github.com/ehmicky/error-serializer#additional-error-properties ) .
102+ [ Plugin options] ( https://github.com/ehmicky/modern-errors#plugin-options ) are
103+ also preserved.
103104
104- ## BaseError.parse(errorObject )
105+ ## BaseError.parse(value )
105106
106- ` errorObject ` : ` ErrorObject ` \
107- _ Return value _ : ` ErrorInstance `
107+ If ` value ` is an error plain object, converts it to an identical error instance.
108+ The original error class is preserved.
108109
109- Converts an error plain object back to an identical error instance. The original
110- error class is preserved .
110+ Otherwise, [ recurse ] ( #deep-serializationparsing ) over ` value ` and parse any
111+ nested error plain object .
111112
112113# Usage
113114
@@ -187,15 +188,13 @@ const newError = BaseError.parse(errorObject)
187188// [errors]: [ExampleError: one, ExampleError: two]
188189```
189190
190- ## Constructor's arguments
191+ ## Constructors
191192
192- Error classes with a
193- [ ` custom ` option] ( https://github.com/ehmicky/modern-errors#-custom-logic )
194- preserve any arguments passed to their ` constructor() ` providing those are both:
195-
196- - Forwarded as is to
197- [ ` super(...) ` ] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super )
198- - Serializable with JSON
193+ If an error with a
194+ [ ` custom ` class] ( https://github.com/ehmicky/modern-errors#-custom-logic ) , is
195+ parsed, its custom constructor is not called. However, any property previously
196+ set by that constructor is still preserved, providing it is serializable and
197+ enumerable.
199198
200199<!-- eslint-disable fp/no-this, fp/no-mutation -->
201200
@@ -211,9 +210,8 @@ const InputError = BaseError.subclass('InputError', {
211210
212211const error = new InputError (' Wrong file.' , {}, true )
213212const errorObject = error .toJSON ()
214-
215- // This calls `new InputError('Wrong file.', {}, true)`
216213const newError = BaseError .parse (errorObject)
214+ console .log (newError .prop ) // true
217215```
218216
219217# Related projects
0 commit comments