clierr

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clierr defines the CLI's error type.

Every failure the user or an agent sees is one of these. That matters more than it might sound: an agent cannot branch on prose, so an error has to carry a stable machine-readable class, a stable code, and a suggested next action, in addition to a sentence a human can read.

The contract, which the documentation states loudly:

branch on Kind or Code, never on Message.

Kind and Code are frozen once shipped and only ever added to. Message is free to change with every release.

This package deliberately depends on nothing. Both the API client and the commands construct these, and neither should have to import the other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCodeOf

func ExitCodeOf(err error) int

ExitCodeOf returns the exit status for any error, so callers do not have to type-switch. An error that is not one of ours is an internal failure, which is honest: it means we did not anticipate it.

Types

type Error

type Error struct {
	Kind Kind `json:"kind"`

	// Code is the fine-grained, stable identifier: "app.name_taken".
	// It is optional; a Kind alone is a valid error. When present it is frozen
	// forever, because agents build handlers keyed on it.
	Code string `json:"code,omitempty"`

	// Message is for a person. It may come verbatim from the API for 4xx
	// responses, where the text is hand-written and actionable. It is never
	// taken from a 500, where it could be any .NET exception string and might
	// carry a connection string or a SQL fragment.
	Message string `json:"message"`

	// Hint is our advice, added on top of whatever the server said.
	Hint string `json:"hint,omitempty"`

	// NextSteps are runnable. Populating this is the difference between an
	// error that stops someone and an error that moves them forward.
	NextSteps []Step `json:"next_steps,omitempty"`

	Retryable bool `json:"retryable"`

	// RetryAfter is seconds, when the server told us.
	RetryAfter int `json:"retry_after,omitempty"`

	// ConfirmCommand is set only for KindConfirmation. It is the exact
	// invocation that would proceed, so the approval decision can be handed to
	// a human, a CI gate or an agent harness without anyone having to
	// reconstruct the command.
	ConfirmCommand []string `json:"confirm_command,omitempty"`

	DocsURL string `json:"docs_url,omitempty"`

	// RequestID ties a failure to a server-side log entry. It is the only
	// thing a user can give support when the message itself is deliberately
	// generic, which is exactly the 500 case.
	RequestID string `json:"request_id,omitempty"`

	// Details carries structured context, such as the raw API message on a
	// 500 or the fields that failed validation. Never rendered in text mode.
	Details map[string]any `json:"details,omitempty"`
	// contains filtered or unexported fields
}

Error is a CLI error.

Field order below is the order it is rendered in, both as JSON and as text, so that reading the struct tells you what the user will see.

func AsError

func AsError(err error) *Error

AsError converts any error into a *Error, wrapping unrecognised ones as internal failures so that rendering never has to handle two shapes.

func Cancelled

func Cancelled(ctx context.Context, message string) *Error

Cancelled turns an interrupted context into the error it actually is, or returns nil when nothing was interrupted.

Every loop that polls needs this. An interrupt cancels whatever request is in flight, so the request fails, and a loop that reads that failure at face value draws the wrong conclusion: at best it announces a network problem that never happened, at worst it decides the stream ended normally and exits 0 on a command the user cut short.

It takes the message rather than inventing one because each loop knows what it was doing: "stopped following" and "interrupted while waiting" are the same event described from different commands.

func Exit

func Exit(status int) *Error

Exit is a non-zero exit status and nothing else.

One command needs it. `env run` hands the terminal to somebody else's program, and when that program exits 1 the CLI has to exit 1: a caller testing the status is asking about the command they ran, not about the tool that started it. There is nothing to print either, because the program has already said whatever it had to say, and an "Error:" line on top of it would be the CLI taking the blame for a failure that is not its own.

It travels as an error because that is the only channel a handler has for ending a command, not because anything went wrong here.

func New

func New(kind Kind, format string, args ...any) *Error

New builds an error of the given kind.

func (*Error) Error

func (e *Error) Error() string

func (*Error) ExitCode

func (e *Error) ExitCode() int

ExitCode is what the process should exit with. The kind decides, unless the error carries a status of its own.

func (*Error) Silent

func (e *Error) Silent() bool

Silent reports an error with nothing to say. See Exit.

func (*Error) WithCode

func (e *Error) WithCode(code string) *Error

WithCode attaches a stable fine-grained code.

func (*Error) WithConfirmCommand

func (e *Error) WithConfirmCommand(argv ...string) *Error

WithConfirmCommand attaches the exact command that would proceed.

It exists so the caller never has to reconstruct it. A destructive command refuses with an argv the reader can hand to a person, paste into an approval or replay verbatim, which is what makes exit 4 a step in a workflow rather than a dead end.

func (*Error) WithDetail

func (e *Error) WithDetail(key string, value any) *Error

WithDetail attaches one structured detail.

func (*Error) WithHint

func (e *Error) WithHint(format string, args ...any) *Error

WithHint attaches advice.

func (*Error) WithRequestID

func (e *Error) WithRequestID(id string) *Error

WithRequestID attaches the server's request identifier.

func (*Error) WithStep

func (e *Error) WithStep(why string, argv ...string) *Error

WithStep appends a runnable next action.

type ExitCode

type ExitCode struct {
	Code int    `json:"code"`
	Kind string `json:"kind,omitempty"`
	What string `json:"what"`

	// Detail is the same thing said in full, for the schema and the
	// documentation, where there is room for a sentence and no column to fit.
	Detail string `json:"detail,omitempty"`

	// Retryable says whether the same command could plausibly work if run
	// again without changing anything. It is the difference between a caller
	// backing off and a caller looping forever.
	Retryable bool `json:"retryable"`
}

ExitCode is one entry in the table.

func ExitCodes

func ExitCodes() []ExitCode

ExitCodes is the whole table, in the order somebody reads it.

type Kind

type Kind string

Kind is the coarse error class. The set is closed and small enough that a caller who knows nothing about Out Plane can handle it exhaustively.

Each Kind maps to exactly one exit code, so a shell script can branch on the exit status alone without parsing anything.

const (
	KindUsage        Kind = "usage"                 // exit 2
	KindAuth         Kind = "auth"                  // exit 3
	KindConfirmation Kind = "confirmation_required" // exit 4
	KindNotFound     Kind = "not_found"             // exit 5
	KindConflict     Kind = "conflict"              // exit 6
	KindQuota        Kind = "quota"                 // exit 7
	KindUpstream     Kind = "upstream"              // exit 8
	KindTimeout      Kind = "timeout"               // exit 124
	KindInterrupted  Kind = "interrupted"           // exit 130
	KindInternal     Kind = "internal"              // exit 1

	// KindUpgradeRequired is the API refusing to serve this release at all.
	//
	// Its own code, rather than folding into usage or upstream, because it is
	// the one failure with a single known remedy that a pipeline can act on
	// without a human: run `outplane update`. Nothing about the request or the
	// credential is wrong, so pointing at either would send the reader looking
	// in the wrong place.
	KindUpgradeRequired Kind = "upgrade_required" // exit 9
)

func (Kind) ExitCode

func (k Kind) ExitCode() int

ExitCode returns the process exit status for a kind.

These values are a public contract. Append only. Never reuse a number and never change what one means: callers pin them in scripts we cannot see.

Read from the table in table.go, which is the only place the numbers are written down. A kind with no entry there is a kind nobody documented, and 1 is what an undocumented failure is.

func (Kind) Retryable

func (k Kind) Retryable() bool

Retryable reports whether trying the same thing again could plausibly work.

Note that quota is NOT retryable, even though it arrives as HTTP 429. The Out Plane API has no rate limiter anywhere; 429 means "this team is over its plan limit". An agent that treats it as backpressure will retry forever against a wall.

type Step

type Step struct {
	Why  string   `json:"why"`
	Argv []string `json:"argv"`
}

Step is a suggested next action.

Argv rather than a string, so an agent can execute it directly with no shell tokenisation, and so quoting bugs cannot turn a suggestion into a different command than the one we meant.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL