Skip to content

Commit

Permalink
fix(src): add trap door to alert developer when erroneously re-enteri…
Browse files Browse the repository at this point in the history
…ng top-level error handler
  • Loading branch information
Xunnamius committed Jul 12, 2024
1 parent 3a339af commit 99e2b3a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export async function runProgram<
let configurationHooks: ConfigurationHooks | undefined = undefined;
let preExecutionContext: PreExecutionContext | undefined = undefined;
let successfullyHandledErrorViaConfigurationHook = false;
let alreadyDidErrorHandling = false;

try {
if (typeof args[1] === 'string' || Array.isArray(args[1])) {
Expand Down Expand Up @@ -393,11 +394,26 @@ export async function runProgram<
debug_('runProgram invocation succeeded');
return parsedArgv;
} catch (error) {
if (alreadyDidErrorHandling) {
debug_.warn(
`discarding exception from ${
preExecutionContext ? '::execute' : '::configureProgram'
} because error handling already happened: %O`,
error
);

debug_.message(
'note that seeing the above message may be a code smell. Check the documentation on CliError::dangerouslyFatal for more information'
);
}

alreadyDidErrorHandling = true;

debug_.error(
`handling irrecoverable exception from ${
preExecutionContext ? '::execute' : '::configureProgram'
}: %O`,
`${error}`
error
);

process.exitCode = isCliError(error)
Expand Down

0 comments on commit 99e2b3a

Please sign in to comment.