diff --git a/lib/cli/handle-error.js b/lib/cli/handle-error.js index 8e3439dea..8f07c16ba 100644 --- a/lib/cli/handle-error.js +++ b/lib/cli/handle-error.js @@ -36,6 +36,8 @@ const writeMessage = (title, message) => { consoleLog(' '); }; +const isErrorCodeNormative = RegExp.prototype.test.bind(/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/); + module.exports = async (exception, options = {}) => { if (!isObject(options)) options = {}; // Due to the fact that the handler can be invoked via fallback, we need to support both `serverless` @@ -167,7 +169,7 @@ module.exports = async (exception, options = {}) => { code: exception.code, }; - if (!isUserError || !exception.code) { + if (!isUserError || !exception.code || !isErrorCodeNormative(exception.code)) { failureReason.location = resolveErrorLocation(exceptionTokens); } await storeTelemetryLocally({ ...telemetryPayload, failureReason, outcome: 'failure' });