Skip to content

Commit 6f4f1ba

Browse files
committed
Improve parser error handling
1 parent 68fe04a commit 6f4f1ba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/interactive-command.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type OptionValueSource,
77
type OptionValues,
88
Option,
9+
CommanderError,
910
} from "commander";
1011
import { partialParse } from "parse-my-command";
1112

@@ -109,7 +110,17 @@ export class InteractiveCommand extends Command {
109110
this._providedOptions = providedOptions;
110111
this._missingOptions = missingOptions;
111112
this._providedOptionsSources = providedOptionsSources;
112-
} catch {}
113+
} catch (error) {
114+
if (!(error instanceof CommanderError)) {
115+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
116+
throw error;
117+
}
118+
119+
// Is this enough?
120+
if (!["commander.helpDisplayed"].includes(error.code)) {
121+
super.error(error.message, error);
122+
}
123+
}
113124

114125
// Even if we prompt for the missing options of the root command here, there
115126
// is no easy way to feed them into super.parseAsync. Therefore, interactive

0 commit comments

Comments
 (0)