Skip to content

Commit 3fb4ae9

Browse files
committed
refactor(cli): rename validation-errors to arg-errors
`validation-errors` collided with the env-graph's own ValidationError, which is about config item values failing their schema and is part of the public API. This module is about the CLI arguments themselves, so name it for that. `isArgValidationError` becomes `isArgError` for the same reason.
1 parent c72b19d commit 3fb4ae9

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

packages/varlock/src/cli/cli-executable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CliExitError } from './helpers/exit-error';
1010
import { fmt } from './helpers/pretty-format';
1111
import { trackCommand, trackInstall } from './helpers/telemetry';
1212
import { InvalidEnvError } from './helpers/error-checks';
13-
import { isArgValidationError, toCliExitError } from './helpers/validation-errors';
13+
import { isArgError, toCliExitError } from './helpers/arg-errors';
1414
import { checkBunVersion } from '../lib/check-bun-version';
1515
import { checkLocalVersionMismatch } from '../lib/check-local-version';
1616
import packageJson from '../../package.json';
@@ -159,7 +159,7 @@ subCommands.set('proxy', buildLazyCommand(proxyCommandSpec, async () => await im
159159
}
160160
gracefulExit();
161161
} catch (error) {
162-
if (isArgValidationError(error)) {
162+
if (isArgError(error)) {
163163
console.error(toCliExitError(error, process.argv.slice(2)).getFormattedOutput());
164164
} else if (error instanceof Error && error.message.startsWith('Command not found: ')) {
165165
const badCommandName = error.message.split(': ')[1];

packages/varlock/src/cli/helpers/validation-errors.ts renamed to packages/varlock/src/cli/helpers/arg-errors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { CliExitError } from './exit-error';
22
import { fmt } from './pretty-format';
33

4+
// Errors about the CLI arguments themselves - unrelated to the env-graph's ValidationError,
5+
// which is about config item values failing their schema.
6+
//
47
// gunshi reports argument problems (unknown options under `strict`, bad enum/type values,
58
// unresolvable subcommands) as an AggregateError of structured errors, and renders them
69
// with `ctx.log` - i.e. stdout, which would corrupt the output of commands like
@@ -99,8 +102,8 @@ export function commandPathFromArgs(args: Array<string>) {
99102
return path;
100103
}
101104

102-
/** Does this error (or aggregate) come from gunshi's argument validation? */
103-
export function isArgValidationError(err: unknown): err is AggregateError {
105+
/** Does this error come from gunshi's argument parsing (unknown flag/command, bad value)? */
106+
export function isArgError(err: unknown): err is AggregateError {
104107
return err instanceof AggregateError && Array.isArray(err.errors);
105108
}
106109

packages/varlock/src/cli/helpers/test/validation-errors.test.ts renamed to packages/varlock/src/cli/helpers/test/arg-errors.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
levenshtein,
44
suggestClosest,
55
commandPathFromArgs,
6-
isArgValidationError,
6+
isArgError,
77
toCliExitError,
8-
} from '../validation-errors';
8+
} from '../arg-errors';
99

1010
/** Shape of gunshi's unknown-option error (matched structurally, never by instanceof) */
1111
const unknownOption = (rawName: string, candidates: Array<string>) => ({
@@ -64,11 +64,11 @@ describe('commandPathFromArgs', () => {
6464
});
6565
});
6666

67-
describe('isArgValidationError', () => {
67+
describe('isArgError', () => {
6868
it('only matches an AggregateError', () => {
69-
expect(isArgValidationError(new AggregateError([]))).toBe(true);
70-
expect(isArgValidationError(new Error('boom'))).toBe(false);
71-
expect(isArgValidationError(undefined)).toBe(false);
69+
expect(isArgError(new AggregateError([]))).toBe(true);
70+
expect(isArgError(new Error('boom'))).toBe(false);
71+
expect(isArgError(undefined)).toBe(false);
7272
});
7373
});
7474

0 commit comments

Comments
 (0)