Skip to content

Commit

Permalink
fix: peserve original error coming from failed flag parsing (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Dec 8, 2023
1 parent 418c732 commit a7a3bba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 0 additions & 10 deletions src/parser/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
})
}
}
8 changes: 6 additions & 2 deletions src/parser/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-await-in-loop */
import {createInterface} from 'node:readline'

import Cache from '../cache'
import {
ArgParserContext,
ArgToken,
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit a7a3bba

Please sign in to comment.