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 ¶
- func ExitCodeOf(err error) int
- type Error
- func (e *Error) Error() string
- func (e *Error) ExitCode() int
- func (e *Error) Silent() bool
- func (e *Error) WithCode(code string) *Error
- func (e *Error) WithConfirmCommand(argv ...string) *Error
- func (e *Error) WithDetail(key string, value any) *Error
- func (e *Error) WithHint(format string, args ...any) *Error
- func (e *Error) WithRequestID(id string) *Error
- func (e *Error) WithStep(why string, argv ...string) *Error
- type ExitCode
- type Kind
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExitCodeOf ¶
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 ¶
AsError converts any error into a *Error, wrapping unrecognised ones as internal failures so that rendering never has to handle two shapes.
func Cancelled ¶
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 ¶
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 (*Error) ExitCode ¶
ExitCode is what the process should exit with. The kind decides, unless the error carries a status of its own.
func (*Error) WithConfirmCommand ¶
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 ¶
WithDetail attaches one structured detail.
func (*Error) WithRequestID ¶
WithRequestID attaches the server's request identifier.
type ExitCode ¶
type ExitCode struct {
Code int `json:"code"`
Kind string `json:"kind,omitempty"`
What string `json:"what"`
// 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.
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 ¶
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.
func (Kind) Retryable ¶
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.