feat(cli-v2): add well-known CLI error template registry#16043
Open
iamnamananand996 wants to merge 2 commits into
Open
feat(cli-v2): add well-known CLI error template registry#16043iamnamananand996 wants to merge 2 commits into
iamnamananand996 wants to merge 2 commits into
Conversation
Introduces a registry of named CLI error templates at `packages/cli/cli-v2/src/errors/wellKnown/CliErrors.ts`, mirroring the `MdxErrorCode` pattern for the rest of the CLI. Each template is a tiny factory returning a `CliError` with a fixed code, a templated message, an actionable hint, and (where appropriate) a docs link. Adding a new well-known failure becomes a 5-line PR (template + test + call-site swap), and every consumer gets identical UX automatically. Initial templates: - `AuthRequired` (with optional message override) - `Unauthorized` - `FernYmlNotFound` - `FlagsMutex` - `FlagRequires` - `MissingRequiredFlags` - `FileNotFound` - `UnsupportedValue` - `HttpFetchFailed` - `EmptyStdin` - `ValidationFailed` - `InternalError` Migrates representative call sites in: - `sdk generate` (4 mutex/requires flag checks) - `sdk add` (4 sites: fern.yml missing, missing flag, duplicate target, unsupported language) - `auth whoami` (auth-required path) - `ApiSpecResolver` (3 sites: empty stdin, missing file, HTTP fetch failure) 14 new unit tests cover every template plus a smoke test that every entry returns a non-empty hint or docs link.
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
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.
4 tasks
Update CliErrors and tests to improve hints and formatting: change supported wording to "Supported <what> values", ensure HttpFetchFailed omits an extra space when statusText is empty, and update tests to expect these hints and message formatting. Fix whoami command to return after writing JSON when --json is used (avoid throwing an auth error after emitting JSON). Also remove the trailing `as const` from the exported FernCliErrors object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Linear ticket: Refs FER-10016
Wave-2 R14 of the cli-v2 error UX/DX cleanup: introduces a registry of well-known CLI error templates, modeled on the existing
MdxErrorCodepattern that the docs MDX parser uses.Stacked on #16040 (wave-1 renderer +
--debug). Re-target tomainafter #16040 merges. Independent of #16041 (R5) and #16042 (R13).Why
Today, ~60 cli-v2 files each call
throw new CliError({ message, code })with their own ad-hoc message. There is no shared catalog of "the well-known ways the Fern CLI can fail", so identical failure modes get inconsistent wording, hints, and docs links across commands. Adding a new typed error requires hand-writing the message, hint, and docsLink at every call site.What
A new
FernCliErrorsregistry atpackages/cli/cli-v2/src/errors/wellKnown/CliErrors.ts. Each entry is a tiny factory that returns a fully-formedCliError— fixed code, templated message, actionable hint, and (where appropriate) a docs link. Adding a new well-known failure becomes a 5-line PR (template + test + call-site swap), and every consumer of that template gets identical UX automatically.Initial templates:
AuthRequiredAUTH_ERRORUnauthorizedAUTH_ERRORFernYmlNotFoundCONFIG_ERRORfern.ymlin cwd or ancestorsFlagsMutexCONFIG_ERRORFlagRequiresCONFIG_ERRORMissingRequiredFlagsCONFIG_ERRORFileNotFoundCONFIG_ERRORUnsupportedValueCONFIG_ERRORHttpFetchFailedNETWORK_ERROREmptyStdinCONFIG_ERROR--api -but nothing piped inValidationFailedVALIDATION_ERRORInternalErrorINTERNAL_ERRORChanges Made
packages/cli/cli-v2/src/errors/wellKnown/CliErrors.tswith the 12 templates above.sdk generate— 4 flag mutex/requires checkssdk add— fern.yml missing, missing required flag, duplicate target (now with hint), unsupported languageauth whoami— auth-required pathApiSpecResolver— empty stdin, missing file, HTTP fetch failurepackages/cli/cli-v2/src/__test__/wellKnownErrors.test.tswith 14 unit tests covering every template + a smoke test that every entry returns a non-empty hint or docs link.packages/cli/cli/changes/unreleased/cli-v2-well-known-errors.yml(feat).Testing
wellKnownErrors.test.ts. Full cli-v2 suite (728 tests) green.pnpm format,pnpm lint:biome,pnpm check,pnpm turbo run compile --filter @fern-api/cli-v2all clean.Future work
error[CODE]in user-facing docs.Link to Devin session: https://app.devin.ai/sessions/c00fe336eaa44387a47db9083451e93c
Requested by: @iamnamananand996