clierr

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

View Source
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.

View Source
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"
)

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

func CodeForStatus(status int, serviceType string) string

CodeForStatus maps an API response status (and the service's own error type, when it sent one) to an error code.

func ExitFor

func ExitFor(code string) int

ExitFor maps an error code to its exit code.

func IsUsage

func IsUsage(err error) bool

IsUsage reports whether err is a usage error, including the plain errors cobra returns for unknown commands and missing or conflicting flags, which can't be wrapped at their source.

func Usage

func Usage(err error) error

Usage wraps err as a usage error. A nil err stays nil.

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": {...}}.

func (*Error) Error

func (e *Error) Error() string

Error is the human form. API errors keep the "service METHOD URL: detail" shape that tells prod from a local backend at a glance.

func (*Error) ExitCode

func (e *Error) ExitCode() int

ExitCode is the process exit code for e.

func (*Error) Unwrap

func (e *Error) Unwrap() 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

Jump to

Keyboard shortcuts

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