Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve original error coming from failed flag parsing #897

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading