Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle errors emitted from SfCommand #432

Merged
merged 10 commits into from
Apr 24, 2023

Conversation

mdonnalley
Copy link
Contributor

@mdonnalley mdonnalley commented Mar 8, 2023

  • Listen for sfCommandError event and send to app insights
  • Removes async event listeners in order to avoid race condition with exit running before cmdErr or sfCommandError have finished running
  • Replace references to targetusername and targetdevhubusername with target-org and target-dev-hub, respectively
  • Removes orgType and apiVersion from COMMAND_ERROR events
  • Adds orgApiVersion, orgId, devhubApiVersion, and devhubId to all COMMAND_ERROR and COMMAND_EXECUTION events
  • Add nuts

@W-12370126@

@mdonnalley mdonnalley changed the title Handle errors emitted from SfCommand fix: handle errors emitted from SfCommand Mar 8, 2023
@cristiand391
Copy link
Member

cristiand391 commented Mar 9, 2023

QA notes:

  1. sfdx plugin link . (plugin-telemetry)
  2. yarn link ('sf-plugins-core` with err event changes)
  3. cd plugin-data && yarn link @salesforce/sf-plugins-core
  4. sfdx plugin link . (plugin-data)

✅ err event object is included in the telemetry payload:
before:

// sf CLI, sfCommand doesn't emit event err
SFDX_TELEMETRY_DEBUG=true DEBUG=* sf data query -q 'hehe' -o cd
...

logs only contains 1 object for the COMMAND_EXECUTION event.

after:

// sfdx CLI with telemetry changes
SFDX_TELEMETRY_DEBUG=true DEBUG=* sfdx data query -q 'hehe' -o cd
..
logs contains 2 objects for the `COMMAND_EXECUTION` and `COMMAND_ERROR` events.

orgType and apiVersion are included in the exception event

✅ devhub org, invalid soql query

sfdx data query -q 'hoho' -o cd
...

in telemetry:
orgType | devhub
apiVersion | 57.0

❌ scratch org, exception event object isn't included in the payload

SFDX_TELEMETRY_DEBUG=true DEBUG=*sfdx:telemetry* s data query -q 'hoho' -o dreamhouse

open log file, you will see the COMMAND_EXECUTION object and not the exception error.

✅ no org specified (also no default org via config). Same scenario if passing an invalid org name|alias:

sfdx data query -q 'hoho'
Error (1): No default environment found. Use -o or --target-org to specify an environment.

in telemetry:
can see exception, orgType and apiVersion aren't defined.

orgId and devHubId not included in COMMAND_EXECUTION event

the code in plugin-telemetry is looking for the sfdx-style org flag names only:

this.orgUsername = flags['targetusername'] as unknown as string;
this.devHubOrgUsername = flags['targetdevhubusername'] as unknown as string;

event.orgId = await getOrgId(false, asString(event.orgUsername));
// eslint-disable-next-line no-await-in-loop
event.devHubId = await getOrgId(true, asString(event.devHubUsername));

@cristiand391 cristiand391 merged commit def30ff into main Apr 24, 2023
@cristiand391 cristiand391 deleted the mdonnalley/sf-command-errors branch April 24, 2023 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants