-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: restore line numbers in bootstrapTest stack traces
pulled from upstream draft endojs/endo#1799
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
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,95 @@ | ||
diff --git a/node_modules/ses/src/commons.js b/node_modules/ses/src/commons.js | ||
index 2d53725..6e385bc 100644 | ||
--- a/node_modules/ses/src/commons.js | ||
+++ b/node_modules/ses/src/commons.js | ||
@@ -213,6 +213,7 @@ export const weaksetAdd = uncurryThis(weaksetPrototype.add); | ||
export const weaksetHas = uncurryThis(weaksetPrototype.has); | ||
// | ||
export const functionToString = uncurryThis(functionPrototype.toString); | ||
+export const errorToString = uncurryThis(Error.prototype.toString); | ||
// | ||
const { all } = Promise; | ||
export const promiseAll = promises => apply(all, Promise, [promises]); | ||
diff --git a/node_modules/ses/src/error/tame-v8-error-constructor.js b/node_modules/ses/src/error/tame-v8-error-constructor.js | ||
index d13744c..e6989f5 100644 | ||
--- a/node_modules/ses/src/error/tame-v8-error-constructor.js | ||
+++ b/node_modules/ses/src/error/tame-v8-error-constructor.js | ||
@@ -8,10 +8,12 @@ import { | ||
arraySlice, | ||
create, | ||
defineProperties, | ||
+ errorToString, | ||
fromEntries, | ||
reflectSet, | ||
regexpExec, | ||
regexpTest, | ||
+ stringReplace, | ||
weakmapGet, | ||
weakmapSet, | ||
weaksetAdd, | ||
@@ -260,7 +262,7 @@ export const tameV8ErrorConstructor = ( | ||
if (errorTaming === 'unsafe') { | ||
const stackString = stackStringFromSST(error, sst); | ||
weakmapSet(stackInfos, error, { stackString }); | ||
- return `${error}${stackString}`; | ||
+ return `${errorToString(error)}${stackString}`; | ||
} else { | ||
weakmapSet(stackInfos, error, { callSites: sst }); | ||
return ''; | ||
@@ -285,7 +287,7 @@ export const tameV8ErrorConstructor = ( | ||
|
||
const defaultPrepareFn = tamedMethods.prepareStackTrace; | ||
|
||
- OriginalError.prepareStackTrace = defaultPrepareFn; | ||
+ const originalPrepareStackTrace = OriginalError.prepareStackTrace; | ||
|
||
// A weakset branding some functions as system prepareFns, all of which | ||
// must be defined by this module, since they can receive an | ||
@@ -299,8 +301,37 @@ export const tameV8ErrorConstructor = ( | ||
// Use concise methods to obtain named functions without constructors. | ||
const systemMethods = { | ||
prepareStackTrace(error, sst) { | ||
- weakmapSet(stackInfos, error, { callSites: sst }); | ||
- return inputPrepareFn(error, safeV8SST(sst)); | ||
+ const stackInfo = {}; | ||
+ const safeCallSites = safeV8SST(sst); | ||
+ let preparedStack; | ||
+ try { | ||
+ preparedStack = inputPrepareFn(error, safeCallSites); | ||
+ if (preparedStack === safeCallSites) { | ||
+ // Handle depd and similar prepareStackTrace which return the structured stack trace | ||
+ stackInfo.callSites = sst; | ||
+ return safeCallSites; | ||
+ } else if ( | ||
+ typeof preparedStack === 'string' && | ||
+ preparedStack !== '' | ||
+ ) { | ||
+ stackInfo.stackString = stringReplace(preparedStack, /^[\n]+/, ''); | ||
+ } else { | ||
+ // We just need to get to the `catch` clause | ||
+ // eslint-disable-next-line no-throw-literal | ||
+ throw undefined; | ||
+ } | ||
+ } catch (_err) { | ||
+ if (errorTaming === 'unsafe') { | ||
+ stackInfo.stackString = stackStringFromSST(error, sst); | ||
+ preparedStack = `${errorToString(error)}${stackInfo.stackString}`; | ||
+ } else { | ||
+ stackInfo.callSites = sst; | ||
+ } | ||
+ } finally { | ||
+ weakmapSet(stackInfos, error, stackInfo); | ||
+ } | ||
+ | ||
+ return errorTaming === 'unsafe' ? preparedStack : ''; | ||
}, | ||
}; | ||
weaksetAdd(systemPrepareFnSet, systemMethods.prepareStackTrace); | ||
@@ -333,5 +364,7 @@ export const tameV8ErrorConstructor = ( | ||
}, | ||
}); | ||
|
||
+ InitialError.prepareStackTrace = originalPrepareStackTrace; | ||
+ | ||
return tamedMethods.getStackString; | ||
}; |