@@ -144,6 +144,50 @@ describe('WorkerRuntime', function () {
144
144
. to . have . property ( 'stack' )
145
145
. matches ( / S y n t a x E r r o r : S y n t a x ! / ) ;
146
146
} ) ;
147
+
148
+ it ( 'COMPASS-5919 - correctly serializes babel parse errors' , async function ( ) {
149
+ /**
150
+ * babel syntax errors have a `clone()` method, which breaks structured cloning
151
+ */
152
+ runtime = new WorkerRuntime ( 'mongodb://nodb/' , dummyOptions , {
153
+ nodb : true ,
154
+ } ) ;
155
+
156
+ const err : Error = await runtime . evaluate ( '1 +* 3' ) . catch ( ( e ) => e ) ;
157
+
158
+ expect ( err ) . to . be . instanceof ( Error ) ;
159
+ expect ( err ) . to . have . property ( 'name' , 'SyntaxError' ) ;
160
+ } ) ;
161
+
162
+ context (
163
+ 'when `evaluate` returns an error that has a function property' ,
164
+ function ( ) {
165
+ it ( 'removes the function property from the error' , async function ( ) {
166
+ runtime = new WorkerRuntime ( 'mongodb://nodb/' , dummyOptions , {
167
+ nodb : true ,
168
+ } ) ;
169
+
170
+ const script = `
171
+ class CustomError extends Error {
172
+ constructor() {
173
+ super('custom error');
174
+ }
175
+ foo() {
176
+ return 'hello, world';
177
+ }
178
+ }
179
+ throw new CustomError();
180
+ ` ;
181
+
182
+ const err : Error = await runtime . evaluate ( script ) . catch ( ( e ) => e ) ;
183
+
184
+ expect ( err ) . to . be . instanceof ( Error ) ;
185
+ expect ( err ) . to . have . property ( 'name' , 'Error' ) ;
186
+ expect ( err ) . not . to . have . property ( 'foo' ) ;
187
+ expect ( err ) . to . have . property ( 'message' , 'custom error' ) ;
188
+ } ) ;
189
+ }
190
+ ) ;
147
191
} ) ;
148
192
} ) ;
149
193
0 commit comments