Skip to content

Commit

Permalink
fix(Telemetry): Ensure to gently handle older globals
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 1, 2021
1 parent 334876e commit 1b90dfb
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions lib/cli/handle-error.js
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1b90dfb

Please sign in to comment.