@mongosh/node-runtime-worker-thread 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +1 -0
- package/dist/child-process-proxy.js +1 -1
- package/dist/index.js +1 -1
- package/dist/report.html +2 -2
- package/dist/serializer.js +3 -1
- package/dist/serializer.js.map +1 -1
- package/dist/worker-runtime.js +3 -3
- package/package.json +7 -7
- package/src/index.spec.ts +44 -0
- package/src/serializer.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/node-runtime-worker-thread",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "MongoDB shell runtime that lives in a worker thread",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
|
|
38
38
|
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
|
39
39
|
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
|
|
40
|
-
"@mongosh/browser-runtime-core": "2.1.
|
|
41
|
-
"@mongosh/browser-runtime-electron": "2.1.
|
|
42
|
-
"@mongosh/service-provider-core": "2.1.
|
|
43
|
-
"@mongosh/service-provider-server": "2.1.
|
|
44
|
-
"@mongosh/types": "2.1.
|
|
40
|
+
"@mongosh/browser-runtime-core": "2.1.1",
|
|
41
|
+
"@mongosh/browser-runtime-electron": "2.1.1",
|
|
42
|
+
"@mongosh/service-provider-core": "2.1.1",
|
|
43
|
+
"@mongosh/service-provider-server": "2.1.1",
|
|
44
|
+
"@mongosh/types": "2.1.1",
|
|
45
45
|
"bson": "^6.2.0",
|
|
46
46
|
"depcheck": "^1.4.3",
|
|
47
47
|
"eslint": "^7.25.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"interruptor": "^1.0.1",
|
|
55
55
|
"system-ca": "^1.0.2"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "c7e70b65988d21c9020abf2bbd253a94b1d3316c"
|
|
58
58
|
}
|
package/src/index.spec.ts
CHANGED
|
@@ -144,6 +144,50 @@ describe('WorkerRuntime', function () {
|
|
|
144
144
|
.to.have.property('stack')
|
|
145
145
|
.matches(/SyntaxError: Syntax!/);
|
|
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
|
|
package/src/serializer.ts
CHANGED
|
@@ -27,7 +27,10 @@ function getNames<T>(obj: T): (keyof T)[] {
|
|
|
27
27
|
*/
|
|
28
28
|
export function serializeError(err: Error) {
|
|
29
29
|
// Name is the only constructor property we care about
|
|
30
|
-
const keys = getNames(err)
|
|
30
|
+
const keys = getNames(err)
|
|
31
|
+
.concat('name')
|
|
32
|
+
// structured cloning cannot handle functions
|
|
33
|
+
.filter((key) => typeof err[key] !== 'function');
|
|
31
34
|
return keys.reduce((acc, key) => {
|
|
32
35
|
(acc as any)[key] = err[key];
|
|
33
36
|
return acc;
|