Skip to content

chore(cli): migrate @fern-api/cli-v2 to use CliError#14992

Open
FedeZara wants to merge 2 commits intomainfrom
FedeZara/refactor/cli-error-cli-v2
Open

chore(cli): migrate @fern-api/cli-v2 to use CliError#14992
FedeZara wants to merge 2 commits intomainfrom
FedeZara/refactor/cli-error-cli-v2

Conversation

@FedeZara
Copy link
Copy Markdown
Contributor

@FedeZara FedeZara commented Apr 14, 2026

Description

Migrates @fern-api/cli-v2 (the next-generation CLI package) to use explicit CliError error codes on every failAndThrow / failWithoutThrowing call site.

This is one of the package migration PRs that follow the error classification system introduced in #14749.

Changes Made

Assigned typed error codes across 48+ call sites in packages/cli/cli-v2/src/, covering every command handler and shared utility. Also fixed test files to match the async createTestContext signature and the TaskAbortSignal throw type for validation errors.

Error codes used

Code Usage
CONFIG_ERROR Missing config, invalid flags, API not found, multiple APIs without selection
AUTH_ERROR Authentication failures, keyring unavailability, login/logout/switch errors
NETWORK_ERROR HTTP/API call failures, docs publishing errors
VALIDATION_ERROR Schema validation failures, docs/SDK check violations
PARSE_ERROR Malformed YAML/JSON, invalid workspace definitions
VERSION_ERROR Generator version incompatibility
ENVIRONMENT_ERROR Missing prerequisites, directory resolution failures
INTERNAL_ERROR Unexpected states indicating bugs

Files touched (grouped by area)

  • API commands: api/check/, api/compile/, api/merge/, api/split/, api/utils/loadSpec.ts
  • Auth commands: auth/login/, auth/logout/, auth/switch/, auth/token/, auth/whoami/
  • Docs commands: docs/check/, docs/dev/, docs/preview/, docs/preview/delete/, docs/publish/
  • SDK commands: sdk/add/, sdk/check/, sdk/generate/, sdk/preview/, sdk/update/
  • Other commands: check/, config/migrate/, init/, org/create/, org/list/
  • Context & errors: Context.ts, withContext.ts, TaskContextAdapter.ts, FernYmlEditor.ts, DocsChecker.ts
  • Telemetry: TelemetryClient.ts, LifecycleEvent.ts
  • Error types: Deleted errors/CliError.ts (replaced by shared @fern-api/task-context CliError), updated ValidationError.ts, SourcedValidationError.ts, KeyringUnavailableError.ts
  • Tests: GeneratorPipeline.test.ts, compile.test.ts, TelemetryClient.test.ts, and all test context utilities

Testing

  • Existing tests pass (309/309 in cli-v2, excluding e2e)

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@FedeZara FedeZara changed the title refactor(cli): rename FernCliError to TaskAbortSignal chore(cli): migrate @fern-api/cli-v2 to use CliError Apr 14, 2026
@FedeZara FedeZara force-pushed the FedeZara/refactor/cli-error-cli-v2 branch 3 times, most recently from 351512a to caecd6f Compare April 14, 2026 23:31
@FedeZara FedeZara marked this pull request as ready for review April 17, 2026 10:03
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@FedeZara FedeZara force-pushed the FedeZara/refactor/cli-error-cli-v2 branch from caecd6f to 0043b24 Compare April 17, 2026 10:03
Comment thread packages/cli/cli-v2/src/commands/sdk/generate/parseOutputArg.ts
Comment thread packages/cli/cli-v2/src/init/Wizard.ts
@FedeZara FedeZara requested a review from fern-support April 17, 2026 10:52
Comment on lines +29 to +34
throw new CliError({
message:
`Could not determine API type for "${reference}". ` +
`File must contain a top-level "openapi" or "asyncapi" key.`,
code: CliError.Code.InternalError
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error code should be ParseError or ConfigError, not InternalError. This error occurs when a user provides an invalid API spec file without the required top-level keys. Using InternalError suggests a bug in the CLI rather than a user configuration issue.

throw new CliError({
    message:
        `Could not determine API type for "${reference}". ` +
        `File must contain a top-level "openapi" or "asyncapi" key.`,
    code: CliError.Code.ParseError
});
Suggested change
throw new CliError({
message:
`Could not determine API type for "${reference}". ` +
`File must contain a top-level "openapi" or "asyncapi" key.`,
code: CliError.Code.InternalError
});
throw new CliError({
message:
`Could not determine API type for "${reference}". ` +
`File must contain a top-level "openapi" or "asyncapi" key.`,
code: CliError.Code.ParseError
});

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@FedeZara FedeZara force-pushed the FedeZara/refactor/cli-error-cli-v2 branch from 628d1ba to 397ce0b Compare April 18, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant