exitcode

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package exitcode provides centralized exit codes for CLI commands. All commands should import this package to ensure consistent exit codes.

Index

Constants

View Source
const (
	// Success indicates successful execution.
	Success = 0

	// GeneralError indicates an unspecified error occurred.
	GeneralError = 1

	// ValidationFailed indicates input validation failed.
	ValidationFailed = 2

	// InvalidInput indicates invalid solution structure (e.g., circular dependency).
	InvalidInput = 3

	// FileNotFound indicates a file was not found or could not be parsed.
	FileNotFound = 4

	// RenderFailed indicates rendering/transformation failed.
	RenderFailed = 5

	// ActionFailed indicates action/workflow execution failed.
	ActionFailed = 6

	// ConfigError indicates a configuration error.
	ConfigError = 7

	// CatalogError indicates a catalog operation failed.
	CatalogError = 8

	// TimeoutError indicates an operation timed out.
	TimeoutError = 9

	// PermissionDenied indicates insufficient permissions.
	PermissionDenied = 10

	// TestFailed indicates one or more functional tests failed.
	TestFailed = 11
)

Standard exit codes for CLI commands. These follow common Unix conventions where possible.

Variables

This section is empty.

Functions

func Description

func Description(code int) string

Description returns a human-readable description of an exit code.

func GetCode

func GetCode(err error) int

GetCode extracts the exit code from an error. Returns GeneralError (1) if the error is not an ExitError. Returns Success (0) if err is nil.

Types

type ExitError

type ExitError struct {
	Err  error
	Code int
}

ExitError wraps an error with an exit code. Commands can return this to indicate a specific exit code should be used. The error message should already be printed by the command before returning.

func AsError

func AsError(err error) *ExitError

AsError creates an ExitError with GeneralError (1) exit code. This is a convenience for commands that just need to signal failure after printing their own error message.

func Errorf

func Errorf(format string, args ...any) *ExitError

Errorf creates an ExitError with GeneralError (1) exit code from a formatted string.

func WithCode

func WithCode(err error, code int) *ExitError

WithCode wraps an error with an exit code. Use this when a command needs to return a specific exit code. The command should print its own error message before calling this.

func (*ExitError) Error

func (e *ExitError) Error() string

Error implements the error interface.

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Unwrap returns the underlying error for errors.Is/As support.

Jump to

Keyboard shortcuts

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