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