Skip to content

Commit

Permalink
Merge pull request #607 from salesforcecli/mdonnalley/check-id
Browse files Browse the repository at this point in the history
fix: only capture errors if id matches
  • Loading branch information
iowillhoit authored Apr 17, 2024
2 parents 0d9b367 + 4995169 commit 5d8a593
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/hooks/telemetryPrerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,19 @@ const hook: Hook.Prerun = async function (options): Promise<void> {
});

// 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 => {
Expand Down

0 comments on commit 5d8a593

Please sign in to comment.