-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ses): test Endo 2355 linenumber workaround
- Loading branch information
Showing
2 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/boot/test/bootstrapTests/stack-linenumbers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
/* | ||
lots of vertical space to test the display of error linenumbers | ||
when running TypeScript tests under Ava on Node. | ||
This is not an automated test of anything. Rather, its purpose is | ||
visual inspection of the output. | ||
With the `SUPPRESS_NODE_ERROR_TAMING` environment variable absent | ||
or set to `'disabled'`, you should see a stack trace that includes | ||
something like | ||
``` | ||
boot/test/bootstrapTests/stack-linenumbers.test.ts:1:104 | ||
``` | ||
This is because the TypeScript compiler compiles this file into one line | ||
of JavaScript with a sourceMap that should map back into original | ||
positions in this file. Node specically makes use of that sourceMap | ||
to produce original linenumbers. However, Node does this in a way | ||
that resists virtualization, so the normal SES error taming cannot use | ||
this sourceMap info. | ||
However, if you also set the `SUPPRESS_NODE_ERROR_TAMING` environment | ||
variable `'enabled'`, for example by doing | ||
```sh | ||
$ export SUPPRESS_NODE_ERROR_TAMING=enabled | ||
``` | ||
at a bash shell, then when you run this test you should instead see | ||
something like | ||
``` | ||
boot/test/bootstrapTests/stack-linenumbers.test.ts:40:32 | ||
``` | ||
*/ | ||
|
||
test('foo', t => { | ||
t.log('look at linenumbers', Error('what me worry')); | ||
t.pass(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
diff --git a/node_modules/ses/src/error/tame-error-constructor.js b/node_modules/ses/src/error/tame-error-constructor.js | ||
index 2788c42..fee98e9 100644 | ||
--- a/node_modules/ses/src/error/tame-error-constructor.js | ||
+++ b/node_modules/ses/src/error/tame-error-constructor.js | ||
@@ -1,3 +1,4 @@ | ||
+import { getEnvironmentOption } from '@endo/env-options'; | ||
import { | ||
FERAL_ERROR, | ||
TypeError, | ||
@@ -7,6 +8,7 @@ import { | ||
setPrototypeOf, | ||
getOwnPropertyDescriptor, | ||
defineProperty, | ||
+ getOwnPropertyDescriptors, | ||
} from '../commons.js'; | ||
import { NativeErrors } from '../permits.js'; | ||
import { tameV8ErrorConstructor } from './tame-v8-error-constructor.js'; | ||
@@ -29,6 +31,7 @@ const tamedMethods = { | ||
return ''; | ||
}, | ||
}; | ||
+let initialGetStackString = tamedMethods.getStackString; | ||
|
||
export default function tameErrorConstructor( | ||
errorTaming = 'safe', | ||
@@ -42,9 +45,25 @@ export default function tameErrorConstructor( | ||
} | ||
const ErrorPrototype = FERAL_ERROR.prototype; | ||
|
||
- const platform = | ||
- typeof FERAL_ERROR.captureStackTrace === 'function' ? 'v8' : 'unknown'; | ||
const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR; | ||
+ let platform = | ||
+ typeof originalCaptureStackTrace === 'function' ? 'v8' : 'unknown'; | ||
+ | ||
+ const SUPPRESS_NODE_ERROR_TAMING = 'SUPPRESS_NODE_ERROR_TAMING'; | ||
+ | ||
+ if ( | ||
+ errorTaming === 'unsafe' && | ||
+ platform === 'v8' && | ||
+ getEnvironmentOption(SUPPRESS_NODE_ERROR_TAMING, 'disabled', [ | ||
+ 'enabled', | ||
+ ]) === 'enabled' | ||
+ ) { | ||
+ // This case is a kludge to work around | ||
+ // https://github.com/endojs/endo/issues/1798 | ||
+ // https://github.com/endojs/endo/issues/2348 | ||
+ // https://github.com/Agoric/agoric-sdk/issues/8662 | ||
+ platform = SUPPRESS_NODE_ERROR_TAMING; | ||
+ } | ||
|
||
const makeErrorConstructor = (_ = {}) => { | ||
// eslint-disable-next-line no-shadow | ||
@@ -122,6 +141,45 @@ export default function tameErrorConstructor( | ||
}, | ||
}); | ||
|
||
+ if (platform === SUPPRESS_NODE_ERROR_TAMING) { | ||
+ // This case is a kludge to work around | ||
+ // https://github.com/endojs/endo/issues/1798 | ||
+ // https://github.com/endojs/endo/issues/2348 | ||
+ // https://github.com/Agoric/agoric-sdk/issues/8662 | ||
+ | ||
+ defineProperties(InitialError, { | ||
+ prepareStackTrace: { | ||
+ get() { | ||
+ return FERAL_ERROR.prepareStackTrace; | ||
+ }, | ||
+ set(newPrepareStackTrace) { | ||
+ FERAL_ERROR.prepareStackTrace = newPrepareStackTrace; | ||
+ }, | ||
+ enumerable: false, | ||
+ configurable: true, | ||
+ }, | ||
+ captureStackTrace: { | ||
+ value: FERAL_ERROR.captureStackTrace, | ||
+ writable: true, | ||
+ enumerable: false, | ||
+ configurable: true, | ||
+ }, | ||
+ }); | ||
+ | ||
+ const descs = getOwnPropertyDescriptors(InitialError); | ||
+ defineProperties(SharedError, { | ||
+ stackTraceLimit: descs.stackTraceLimit, | ||
+ prepareStackTrace: descs.prepareStackTrace, | ||
+ captureStackTrace: descs.captureStackTrace, | ||
+ }) | ||
+ | ||
+ return { | ||
+ '%InitialGetStackString%': initialGetStackString, | ||
+ '%InitialError%': InitialError, | ||
+ '%SharedError%': SharedError, | ||
+ }; | ||
+ } | ||
+ | ||
// The default SharedError much be completely powerless even on v8, | ||
// so the lenient `stackTraceLimit` accessor does nothing on all | ||
// platforms. | ||
@@ -171,7 +229,6 @@ export default function tameErrorConstructor( | ||
}); | ||
} | ||
|
||
- let initialGetStackString = tamedMethods.getStackString; | ||
if (platform === 'v8') { | ||
initialGetStackString = tameV8ErrorConstructor( | ||
FERAL_ERROR, |