Skip to content

chore(cli): migrate @fern-api/cli-logger to use CliError#14990

Closed
FedeZara wants to merge 10 commits intomainfrom
FedeZara/refactor/cli-error-cli-logger
Closed

chore(cli): migrate @fern-api/cli-logger to use CliError#14990
FedeZara wants to merge 10 commits intomainfrom
FedeZara/refactor/cli-error-cli-logger

Conversation

@FedeZara
Copy link
Copy Markdown
Contributor

@FedeZara FedeZara commented Apr 14, 2026

Description

Migrates @fern-api/cli-logger to use the shared CliError infrastructure introduced in the foundational error classification system (#14749). This PR also includes the complete CliError foundation (shared CliError class with typed codes, TaskAbortSignal rename, Sentry routing, and CLI v1/v2 integration) that all subsequent per-package migration PRs build on.

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

Changes Made

Assigned typed error codes and migrated error handling across 86 files spanning the CliError foundation and the @fern-api/cli-logger package-specific migration.

Error codes used

Code Usage
CONFIG_ERROR Missing config, invalid flags, bad file paths, unknown group/generator names
AUTH_ERROR Authentication failures, token creation, keyring unavailability
NETWORK_ERROR HTTP/API call failures, translation service errors
VALIDATION_ERROR Schema validation failures, workspace validation
PARSE_ERROR Malformed YAML/JSON, invalid IR files
VERSION_ERROR Invalid semver, generator version incompatibility
ENVIRONMENT_ERROR Missing prerequisites, Node version checks
INTERNAL_ERROR Unexpected states indicating bugs
RESOLUTION_ERROR Protobuf resolution, spec loading failures
CONTAINER_ERROR Docker/container execution failures
IR_CONVERSION_ERROR IR generation/conversion failures

Files touched (grouped by area)

  • CliError foundation: task-context/src/CliError.ts, TaskAbortSignal.ts, TaskContext.ts, MockTaskContext.ts, index.ts
  • CLI v1 integration: cli-context/CliContext.ts, TaskContextImpl.ts, cli.ts, cliV2.ts, SentryClient.ts
  • CLI v2 integration: context/Context.ts, withContext.ts, TaskContextAdapter.ts, TelemetryClient.ts, all command files
  • CLI Logger (package-specific): cli-logger/src/logErrorMessage.ts — migrated FernCliError to TaskAbortSignal, added Node 18+ detection
  • Seed: TaskContextImpl.ts, TaskContextFactory.ts, logErrorMessage.ts
  • Other packages: login/, snippets/core/, ir-generator/, local-workspace-runner/, remote-workspace-runner/, configuration-loader/, lazy-fern-workspace/

Testing

  • Existing tests pass (pnpm test, excluding e2e and pre-existing environment failures)

FedeZara added 10 commits April 9, 2026 23:52
…entry routing

Introduce CliError with 12-code union (INTERNAL_ERROR, PARSE_ERROR,
CONFIG_ERROR, etc.) in @fern-api/task-context. Add captureException to
TaskContext interface. Wire Sentry reporting into failWithoutThrowing
at point of failure. Update top-level handlers in both CLI v1 and v2
to classify untyped errors as INTERNAL_ERROR.

Made-with: Cursor
…xt CliError

Delete the local cli-v2 CliError class and switch all 31 importing
files to use the shared CliError from @fern-api/task-context. Remap
v2 codes (AUTH_REQUIRED→AUTH_ERROR, EXIT→TaskAbortSignal, etc.),
replace ~35 CliError.exit() calls with TaskAbortSignal, and classify
~62 untyped new CliError sites with appropriate error codes.

Made-with: Cursor
…ingUnavailableError extend CliError

Each subclass now carries a default error code (VALIDATION_ERROR / AUTH_ERROR),
eliminating the need for the separate extractErrorCode and local
shouldReportToSentry functions in withContext.ts. reportError now relies
entirely on resolveErrorCode and the shared shouldReportToSentry from
@fern-api/task-context.

Made-with: Cursor
Adds the error code as an `error.code` tag to Sentry exceptions,
matching the v1 SentryClient behavior. The code is resolved via
resolveErrorCode in both reportError and TaskContextAdapter.

Made-with: Cursor
Replace all LoggableFernCliError throw sites with CliError.internalError()
and remove the dedicated catch branches since CliError is already handled
upstream. Deletes the now-unused LoggableFernCliError class.

Made-with: Cursor
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-logger to use CliError Apr 14, 2026
@FedeZara FedeZara closed this Apr 14, 2026
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