diff --git a/lib/sandbox.js b/lib/sandbox.js index 560f596..d91224b 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -285,9 +285,11 @@ function errorToFault(err) { }; if (err.stack) { + fault.detail.stack = err.stack; // Trim the stack trace at the self-executing anonymous wrapper function - let stackTrimIndex = err.stack.match(/\s+at\s[^\s]+\s+at\s[^\s]+\s\(vm\.js.+\)/).index; - fault.detail.stack = err.stack.slice(0, stackTrimIndex); + let stackTrimIndex = fault.detail.stack.match(/\s+at\s[^\s]+\s+at\s[^\s]+\s\(vm\.js.+\)/); + if (stackTrimIndex) + fault.detail.stack = fault.detail.stack.slice(0, stackTrimIndex.index); } return fault;