From bc8619e19980881c380778ee87c81e25f7ae2965 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Mon, 19 Mar 2018 23:17:39 -0700 Subject: [PATCH] Fix error trying to trim a partial stack trace --- lib/sandbox.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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;