Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix config error checking condition
To maintain parity with the previous logic: only 1 of the 2 conditions needs to hold: either the exit codes match, or the error messages match.
  • Loading branch information
angelapwen committed Feb 6, 2024
commit 34d760ddcc1be566c43710db5d6ea209d8919072
16 changes: 9 additions & 7 deletions lib/cli-config-errors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cli-config-errors.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/cli-config-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export enum CliError {
/**
* All of our caught CLI error messages that we handle specially: ie. if we
* would like to categorize an error as a configuration error or not. Optionally
* associated with a CLI error code as well. Note that the CLI error code, if
* it exists, always takes precedence over the error message snippet.
* associated with a CLI error code as well. Note that either of the conditions
* is enough to be considered a match: if the exit code is a match, or the error
* messages match.
*/
export const cliErrorsConfig: Record<
CliError,
Expand Down Expand Up @@ -48,8 +49,8 @@ export const cliErrorsConfig: Record<

/**
* Checks whether or not the error message received from the CLI is a config
* error: if there is an exit code, this takes precedence. Otherwise, matches
* the error message against the expected message snippets.
* error. Returns true as long as either of the conditions holds: the exit
* codes are a match, or the error message matches the expected message snippets.
*/
export function isCliConfigurationError(
cliError: CliError,
Expand All @@ -58,9 +59,12 @@ export function isCliConfigurationError(
): boolean {
const cliErrorConfig = cliErrorsConfig[cliError];

// If both exit codes exist, exit codes take precedence over message matching.
if (exitCode && cliErrorConfig.exitCode) {
return exitCode === cliErrorConfig.exitCode;
if (
exitCode !== undefined &&
cliErrorConfig.exitCode !== undefined &&
exitCode === cliErrorConfig.exitCode
) {
return true;
}

for (const e of cliErrorConfig.cliErrorMessageSnippets) {
Expand Down