diff --git a/patches/ses+0.18.8.patch b/patches/ses+0.18.8.patch new file mode 100644 index 000000000000..ebcbefd991d2 --- /dev/null +++ b/patches/ses+0.18.8.patch @@ -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; + };