Skip to content

fix(cli): classify github failures and give every error a remedy - #90

Open
FreshlyBrewedCode wants to merge 2 commits into
mainfrom
fix/81-cli-actionable-errors
Open

FreshlyBrewedCode wants to merge 2 commits into
mainfrom
fix/81-cli-actionable-errors

Conversation

@FreshlyBrewedCode

Copy link
Copy Markdown
Owner

closes #81

User-facing change

Every CLI failure now names the actual problem and, where one exists, the remedy. The GitHub transport classifies a non-2xx response and the API layer phrases it in the caller's terms, so the four failures that used to collapse into unexpected status N are now distinct:

  • Invalid or expired credential — says so and names how to supply a working one (gh auth login or GH_TOKEN).
  • Credential that cannot reach the repository — reports the access problem and no longer suggests signing in again.
  • Repository that does not exist or is not visible — names the repository and says it cannot be found or is not visible.
  • Resource that does not exist — names the resource and its repository.
  • Anything else — keeps GitHub's own message alongside the status.

Rate-limit failures keep their existing distinct primary and secondary messages and retry advice.

The sweep also gives previously vague filesystem and server messages a path and a next step, and report.ts now collapses any multi-line diagnosis to a single wayful:-prefixed stderr line, so the single-line/no-stack-trace contract holds even when a backend hands back a multi-line body.

Before / after examples

Invalid credential:

# before
$ wayful map list
wayful: github api request failed: unexpected status 401.

# after
$ wayful map list
wayful: the github credential for acme/widgets is invalid or expired (status 401); run 'gh auth login' or set GH_TOKEN to supply a working token.

Credential that cannot reach the repository:

# before
$ wayful map list
wayful: github api request failed: unexpected status 403.

# after
$ wayful map list
wayful: the github credential is valid but cannot access acme/widgets (status 403); check the token's repository access and scope.

Repository configured but not found/visible:

# before
$ wayful map list
wayful: github api request failed: unexpected status 404.

# after
$ wayful map list
wayful: github cannot find acme/widgets (status 404); it may not exist or may not be visible to the current credential.

Missing resource (e.g. a step):

# before
$ wayful step show 7 --map plan
wayful: github api request failed: unexpected status 404.

# after
$ wayful step show 7 --map plan
wayful: github cannot find issue #7 in acme/widgets (status 404); it may have been deleted, renamed, or not be visible to the current credential.

Filesystem read failures now name the directory and the next step:

# before
$ wayful map list
wayful: cannot read project maps.

# after
$ wayful map list
wayful: cannot read project maps from '/repo/.wayful/maps'; check that it exists and you have permission to read it.

How it works

  • GithubHttp.getJson raises a classified GithubRequestError (unauthenticated / forbidden / not-found / unexpected) instead of a generic unexpected status N.
  • api.ts's githubFailure turns a classification plus the addressed repository/resource into the caller-terms message; every GitHub call site routes its non-2xx path through it.
  • graphql.ts uses the same classification for snapshot reads.
  • oneLine (in domain/errors.ts) collapses multi-line messages; report.ts applies it to every diagnosis.

Tests

  • http.test.ts: status → classification, GitHub message preserved.
  • api.test.ts: credential, access, repository-not-found, resource-not-found, and unexpected-status messages.
  • mapStore.test.ts: listMaps failure messages at the store seam.
  • graphql.test.ts: classified snapshot failures.
  • domain/errors.test.ts: single-line collapsing.

bun check (lint, typecheck, tests) passes.

Non-2xx GitHub responses now carry a classified failure from the transport
(unauthenticated, forbidden, not-found, unexpected). The API layer phrases
each in the caller's terms with the repository or resource it addressed:
an invalid or expired credential names how to supply a working one; a
credential that cannot reach the repository is not told to sign in again;
a missing repository is named and described as not found or not visible;
and an unexpected status keeps GitHub's own message.

The sweep also gives previously vague filesystem and server messages a
path and a next step, and report.ts collapses any multi-line diagnosis to
the single 'wayful:'-prefixed stderr line the contract promises.

closes #81

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): every error says what went wrong and what to do next

1 participant