Skip to content

Commit

Permalink
test: restore line numbers in bootstrapTest stack traces
Browse files Browse the repository at this point in the history
pulled from upstream draft endojs/endo#1799
  • Loading branch information
turadg committed Oct 3, 2023
1 parent 0eb4660 commit 83b1fc8
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions patches/ses+0.18.8.patch
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;
};

0 comments on commit 83b1fc8

Please sign in to comment.