Documentation
¶
Overview ¶
Package clierr holds the CLI's process exit codes and the error types that select them, so scripts can branch on why a command failed.
Index ¶
Constants ¶
const ( ExitOK = 0 ExitError = 1 ExitUsage = 2 // bad flags, arguments or input; fix the command line ExitNotFound = 3 // the resource doesn't exist (API 404) ExitAuth = 4 // not signed in or session expired; run `norcube login` ExitAccess = 5 // signed in, but not allowed (not a member, missing permission or scope) ExitRateLimited = 6 // still throttled (429) after the retries ExitTimeout = 7 // the request timed out ExitConflict = 8 // the request conflicts with the current state (API 409) ExitInterrupted = 130 // SIGINT/SIGTERM, the shell convention 128+2 )
Exit codes, stable for scripts. Anything not listed is 1.
const ( CodeError = "error" CodeUsage = "usage_error" CodeValidation = "validation_failed" CodeOrgNotFound = "org_not_found" CodeNotFound = "not_found" CodeLoginRequired = "login_required" CodePermissionDenied = "permission_denied" CodeInsufficientScope = "insufficient_scope" CodeRateLimited = "rate_limited" CodeTimeout = "timeout" CodeConflict = "conflict" CodeServerError = "server_error" CodeInterrupted = "interrupted" // CodeJobFailed: a command waited (--wait) for a server-side job that // ended unsuccessfully. Exit code 1. CodeJobFailed = "job_failed" // CodeUnhealthy: a command asked to fail on a state it reports // (`monitor status --fail-on`) found it, e.g. an open critical // incident. Exit code 1; details hold what it found. CodeUnhealthy = "unhealthy" )
Error codes: the stable, machine-readable reason in an Error. Scripts match on these (and on the exit code); messages may change wording.
Variables ¶
This section is empty.
Functions ¶
func CodeForStatus ¶
CodeForStatus maps an API response status (and the service's own error type, when it sent one) to an error code.
Types ¶
type Error ¶
type Error struct {
Code string `json:"code" yaml:"code"`
Message string `json:"message" yaml:"message"`
Hint string `json:"hint,omitempty" yaml:"hint,omitempty"`
// HTTPStatus, Service, Method, URL, Type and RequestID describe the
// API response that failed, when there was one.
HTTPStatus int `json:"status,omitempty" yaml:"status,omitempty"`
Service string `json:"service,omitempty" yaml:"service,omitempty"`
Method string `json:"method,omitempty" yaml:"method,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
// Type is the service's own error type (e.g. NOT_FOUND).
Type string `json:"type,omitempty" yaml:"type,omitempty"`
RequestID string `json:"requestId,omitempty" yaml:"requestId,omitempty"`
Details any `json:"details,omitempty" yaml:"details,omitempty"`
// Err is the underlying error, for errors.Is/As.
Err error `json:"-" yaml:"-"`
}
Error is a failure described for both people and scripts. Printed as text it reads like before; with -o json (or NORCUBE_ERROR_FORMAT=json) it is written to stderr as {"error": {...}}.
type UsageError ¶
type UsageError struct{ Err error }
UsageError marks a mistake in how the command was invoked.
func (*UsageError) Error ¶
func (e *UsageError) Error() string
func (*UsageError) Unwrap ¶
func (e *UsageError) Unwrap() error