diff --git a/lib/cli/handle-error.js b/lib/cli/handle-error.js index d68b7151fc9..e925a770f18 100644 --- a/lib/cli/handle-error.js +++ b/lib/cli/handle-error.js @@ -47,14 +47,10 @@ module.exports = async (exception, options = {}) => { isUncaughtException, isLocallyInstalled: passedIsLocallyInstalled, isInvokedByGlobalInstallation: passedIsInvokedByGlobalInstallation, - command, - options: cliOptions, - commandSchema, - serviceDir, - configuration, serverless, hasTelemetryBeenReported, } = options; + let { command, options: cliOptions, commandSchema, serviceDir, configuration } = options; const isLocallyInstalled = serverless ? serverless.isLocallyInstalled : passedIsLocallyInstalled; const isInvokedByGlobalInstallation = serverless @@ -158,27 +154,44 @@ module.exports = async (exception, options = {}) => { if ( !isTelemetryDisabled && hasTelemetryBeenReported === false && - (serverless ? serverless.isTelemetryReportedExternally : true) && - resolveInput().commandSchema // Do not report for unrecognized commands + (serverless ? serverless.isTelemetryReportedExternally : true) ) { - const telemetryPayload = await generateTelemetryPayload({ - command, - options: cliOptions, - commandSchema, - serviceDir, - configuration, - serverless, - }); - const failureReason = { - kind: isUserError ? 'user' : 'programmer', - code: exception.code, - }; - - if (!isUserError || !exception.code || !isErrorCodeNormative(exception.code)) { - failureReason.location = resolveErrorLocation(exceptionTokens); + if (command == null) { + // We're in local fallback and older global didn't pass CLI command data, resolve it here + if (serverless) { + configuration = serverless.configurationInput; + serviceDir = serverless.serviceDir; + } + const commandsSchema = configuration + ? require('./commands-schema/resolve-final')(serverless.pluginManager.externalPlugins, { + providerName: serverless.service.provider.name, + configuration, + }) + : require('./commands-schema/aws-service'); + ({ command, options: cliOptions, commandSchema } = resolveInput(commandsSchema)); + } + + if (commandSchema) { + // Report only for recognized commands + const telemetryPayload = await generateTelemetryPayload({ + command, + options: cliOptions, + commandSchema, + serviceDir, + configuration, + serverless, + }); + const failureReason = { + kind: isUserError ? 'user' : 'programmer', + code: exception.code, + }; + + if (!isUserError || !exception.code || !isErrorCodeNormative(exception.code)) { + failureReason.location = resolveErrorLocation(exceptionTokens); + } + await storeTelemetryLocally({ ...telemetryPayload, failureReason, outcome: 'failure' }); + await sendTelemetry(); } - await storeTelemetryLocally({ ...telemetryPayload, failureReason, outcome: 'failure' }); - await sendTelemetry(); } process.exitCode = 1;