From e10e402d9591daa61c282627795e3f1a8ca9cd03 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 11 Apr 2024 12:35:41 -0600 Subject: [PATCH] fix: only capture errors if id matches --- src/hooks/telemetryPrerun.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hooks/telemetryPrerun.ts b/src/hooks/telemetryPrerun.ts index 6bec7aa3..4c1aa621 100644 --- a/src/hooks/telemetryPrerun.ts +++ b/src/hooks/telemetryPrerun.ts @@ -143,8 +143,19 @@ const hook: Hook.Prerun = async function (options): Promise { }); // Record failed command executions from commands that extend SfCommand - process.on('sfCommandError', (error: SfError) => { - errors.push({ error, event: { ...commandExecution.toJson(), eventName: 'COMMAND_ERROR' } }); + process.on('sfCommandError', (error: SfError, id: string) => { + /** + * Only record the error if the id matches the command name or if the id is not provided. + * + * This is to prevent recording duplicate errors when running multiple commands in the same process + * (e.g. a `plugins install` of a JIT plugin before running the provided command). + * + * We still record the error if no id is provided to ensure we capture all errors for plugins that + * have not updated @salesforce/sf-plugins-core to the version that includes the id parameter + */ + if (id === commandExecution.getCommandName() || !id) { + errors.push({ error, event: { ...commandExecution.toJson(), eventName: 'COMMAND_ERROR' } }); + } }); const commonDataMemoized = (): CommonData => {