Skip to content

errors: internal/errors is dead code; API errors reach users raw (handleError passthrough) #27

Description

@timimsms

Context

The internal/errors package (typed APIError/UserError, HandleHTTPError) is dead code: nothing invokes it, so raw API/HTTP errors reach users unformatted. Error handling style is also split across the command tree, which blocks consistent, structured error output.

Evidence

  • internal/api/client.go:234 — Client.handleError is a passthrough:
// TODO: Parse HTTP response codes and convert to appropriate errors
// For now, return the error as-is
return err
  • internal/errors — HandleHTTPError, APIError, and UserError are never invoked anywhere in the codebase.
  • Command error style is inconsistent: 96 call sites use Run + fmt.Fprintf(os.Stderr, ...) + os.Exit(1), while others use RunE. The os.Exit paths skip cobra's error handling entirely.

Suggested fix

  1. Wire HandleHTTPError into api.Client.handleError so HTTP status codes map to typed, user-friendly errors (401 → "run cu auth login", 404 → resource context, 429 → rate-limit guidance).
  2. Migrate commands from Run+os.Exit to RunE so errors flow through a single formatting point.

This is a prerequisite for the structured JSON error output tracked in #18.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions