From 07d5b9c19e9f5365af322a4862b03ccdca05655c Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 17 May 2021 15:10:38 +0200 Subject: [PATCH] refactor(Telemetry): Report error location for non-normative error codes --- lib/cli/handle-error.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cli/handle-error.js b/lib/cli/handle-error.js index 8e3439dea72..8f07c16ba42 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' });