File tree Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Expand file tree Collapse file tree 3 files changed +47
-6
lines changed Original file line number Diff line number Diff line change @@ -45,10 +45,10 @@ module.exports = {
4545 // An object that configures minimum threshold enforcement for coverage results
4646 coverageThreshold : {
4747 global : {
48- branches : 94.25 ,
48+ branches : 94.31 ,
4949 functions : 94.11 ,
50- lines : 97.04 ,
51- statements : 97.04 ,
50+ lines : 97.05 ,
51+ statements : 97.05 ,
5252 } ,
5353 } ,
5454
Original file line number Diff line number Diff line change @@ -118,6 +118,25 @@ describe('rpcErrors', () => {
118118 } ,
119119 } ) ;
120120 } ) ;
121+
122+ it ( 'serializes a non-Error-instance cause' , ( ) => {
123+ const error = rpcErrors . invalidInput ( {
124+ data : {
125+ foo : 'bar' ,
126+ cause : 'foo' ,
127+ } ,
128+ } ) ;
129+
130+ const serializedError = error . serialize ( ) ;
131+ assert ( serializedError . data ) ;
132+ assert ( isPlainObject ( serializedError . data ) ) ;
133+
134+ expect ( serializedError . data . cause ) . not . toBeInstanceOf ( Error ) ;
135+ expect ( serializedError . data ) . toStrictEqual ( {
136+ foo : 'bar' ,
137+ cause : 'foo' ,
138+ } ) ;
139+ } ) ;
121140} ) ;
122141
123142describe ( 'providerErrors' , ( ) => {
@@ -169,4 +188,23 @@ describe('providerErrors', () => {
169188 } ,
170189 } ) ;
171190 } ) ;
191+
192+ it ( 'serializes a non-Error-instance cause' , ( ) => {
193+ const error = providerErrors . unauthorized ( {
194+ data : {
195+ foo : 'bar' ,
196+ cause : 'foo' ,
197+ } ,
198+ } ) ;
199+
200+ const serializedError = error . serialize ( ) ;
201+ assert ( serializedError . data ) ;
202+ assert ( isPlainObject ( serializedError . data ) ) ;
203+
204+ expect ( serializedError . data . cause ) . not . toBeInstanceOf ( Error ) ;
205+ expect ( serializedError . data ) . toStrictEqual ( {
206+ foo : 'bar' ,
207+ cause : 'foo' ,
208+ } ) ;
209+ } ) ;
172210} ) ;
Original file line number Diff line number Diff line change @@ -14,14 +14,17 @@ import { errorCodes, errorValues } from './error-constants';
1414 * A data object, that must be either:
1515 *
1616 * - A JSON-serializable object.
17- * - An object with a `cause` property that is an `Error` instance , and any
17+ * - An object with a `cause` property that is an error-like value , and any
1818 * other properties that are JSON-serializable.
1919 */
2020export type DataWithOptionalCause =
2121 | Json
2222 | {
23- [ key : string ] : Json | Error ;
24- cause : Error ;
23+ // Unfortunately we can't use just `Json` here, because all properties of
24+ // an object with an index signature must be assignable to the index
25+ // signature's type. So we have to use `Json | unknown` instead.
26+ [ key : string ] : Json | unknown ;
27+ cause : unknown ;
2528 } ;
2629
2730const FALLBACK_ERROR_CODE = errorCodes . rpc . internal ;
You can’t perform that action at this time.
0 commit comments