oclif / core

Node.js Open CLI Framework. Built by Salesforce.

Home Page:https://oclif.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NonExistentFlagException is thrown twice

AllanOricil opened this issue · comments

Describe the bug

While I was fixing this issue I noticed that the NonExistentFlagsError exception was being thrown twice. The first time it is thrown, the exception does not propagate up to the parent's try/catch, just when it is thrown for the second time. I was using a sfdx command so I'm not sure if sfdx is calling the parser again besides oclif call.

To Reproduce

  • Add a breakpoint in the parser, right before the validate call
  • run a sfdx command with a non existent flag, like I did in the images shown in this PR

Expected behavior
NonExistentFlagException must be thrown once when passing 1 or many non existent flags, and the execution should stop right away

Screenshots
I could not take a screenshot of the callstack because I could not display both exceptions at once

Environment (please complete the following information):

MacOS latest
zsh

Additional context
Noticed it while I was creating this fix

I was using a sfdx command so I'm not sure if sfdx is calling the parser again besides oclif call.

This is where the first error is being thrown: https://github.com/salesforcecli/plugin-telemetry/blob/main/src/commandExecution.ts#L143

That parse is attempting to get the provided flags so that it can report it to app insights.

The second parse is done by the command class, so that's where the error gets thrown the second time.

I'm gonna close this since it's not really an issue (at least for oclif/core)