Skip to content

cmd: migrate commands from Run + os.Exit to RunE (part 2 of #27) #58

Open

Description

@timimsms

Context

This is part 2 of #27. Part 1 maps API errors to typed, readable messages in api.Client.handleError. Part 2 makes every command route those errors through one place.

Most commands use Run, print with fmt.Fprintf(os.Stderr, ...) and call os.Exit(1). Others use RunE. The os.Exit paths skip cobra's error handling and deferred cleanup, and every one of them formats its error differently.

Proposal

  • Convert commands to RunE, returning wrapped errors (fmt.Errorf("failed to …: %w", err)).
  • Set SilenceUsage (and SilenceErrors, with cu printing the error itself) on the root command, so runtime failures don't print the usage block while flag and argument errors still do.
  • Format errors once in cmd/cu/main.go. That gives a single place for the structured error envelope for -o json that Add consistent --json output across all commands #18 tracks.
  • Keep the exit-code behaviour: bulk commands exit 1 when any task failed.

Doing this one command group per PR keeps the diffs reviewable and avoids conflicts with feature work.

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    on Nov 18, 2026
  2. timimsms commented on Nov 18, 2026

    @timimsms
    OwnerAuthor

    Notes from part 1 (#64) for this follow-up:

    • Add --debug output at the single formatting point, such as the request URL or the raw SDK error. Today the ECODE always appears in parentheses.
    • GetWorkspaceMembers returns a plain "workspace not found" error; make it a typed not-found error.
    • Optionally run cu api (internal/cmd/api.go, which uses its own HTTP client) through the same status mapping.
    • errors.IsRetryable never matches transport errors, so network failures are never retried. Decide whether they should be.
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions