From a7a3bbabdf2a6cce19dd86583ca91409e0de3123 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 7 Dec 2023 16:02:22 -0800 Subject: [PATCH] fix: peserve original error coming from failed flag parsing (#897) --- src/parser/errors.ts | 10 ---------- src/parser/parse.ts | 8 ++++++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/parser/errors.ts b/src/parser/errors.ts index 5174a9446..802dd4323 100644 --- a/src/parser/errors.ts +++ b/src/parser/errors.ts @@ -119,13 +119,3 @@ export class FailedFlagValidationError extends CLIParseError { super({exit: Cache.getInstance().get('exitCodes')?.failedFlagValidation ?? exit, message, parse}) } } - -export class FailedFlagParsingError extends CLIParseError { - constructor({flag, message}: {flag: string; message: string}) { - super({ - exit: Cache.getInstance().get('exitCodes')?.failedFlagParsing, - message: `Parsing --${flag} \n\t${message}`, - parse: {}, - }) - } -} diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 392a1cca2..14183efc2 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -1,6 +1,7 @@ /* eslint-disable no-await-in-loop */ import {createInterface} from 'node:readline' +import Cache from '../cache' import { ArgParserContext, ArgToken, @@ -19,7 +20,7 @@ import { ParsingToken, } from '../interfaces/parser' import {isTruthy, last, pickBy} from '../util/util' -import {ArgInvalidOptionError, CLIError, FailedFlagParsingError, FlagInvalidOptionError} from './errors' +import {ArgInvalidOptionError, CLIError, FlagInvalidOptionError} from './errors' let debug: any try { @@ -348,7 +349,10 @@ export class Parser< return await flag.parse(input, ctx, flag) } catch (error: any) { - throw new FailedFlagParsingError({flag: flag.name, message: error.message}) + error.message = `Parsing --${flag.name} \n\t${error.message}\nSee more help with --help` + if (Cache.getInstance().get('exitCodes')?.failedFlagParsing) + error.oclif = {exit: Cache.getInstance().get('exitCodes')?.failedFlagParsing} + throw error } }