From bae1f0e9fc24375d37b83cd0ced3f84a862e9be9 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 1 Jul 2020 15:50:15 +0200 Subject: [PATCH] Don't attempt to generate function description when the location of a stacktrace frame could not be determined --- src/aggregrate-errors.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/aggregrate-errors.js b/src/aggregrate-errors.js index 6c26b8e..2527e8d 100644 --- a/src/aggregrate-errors.js +++ b/src/aggregrate-errors.js @@ -142,13 +142,17 @@ module.exports = function aggregrateAndThrowErrors(errors) { let detailLines = renderErrorList(errors); let frame = determineLocation(); - let functionString = (frame.alias != null) - ? `${frame.alias} [${frame.functionName}]` - : frame.functionName; + let locationString = asExpression(() => { + if (frame != null) { + let functionString = (frame.alias != null) + ? `${frame.alias} [${frame.functionName}]` + : frame.functionName; - let locationString = (frame != null) - ? `${highlightBold(functionString)} in ${highlightBold(frame.shortPath)}, at line ${highlightBold(frame.location.line)} (${frame.location.path})` - : dimBold(`(could not determine location)`); + return `${highlightBold(functionString)} in ${highlightBold(frame.shortPath)}, at line ${highlightBold(frame.location.line)} (${frame.location.path})`; + } else { + return dimBold(`(could not determine location)`); + } + }); return new AggregrateValidationError(`One or more validation errors occurred at ${locationString}:\n${detailLines}`, { errors: errors