Documentation
¶
Index ¶
- Constants
- Variables
- func AllErrorCodes() []string
- func IsSilentError(err error) bool
- func Print(v any)
- func PrintError(code int, message, suggestion string)
- func PrintStructuredError(e StructuredError)
- func PrintVerbose(format string, args ...any)
- func SetForTest(t interface{ ... }) (stdout, stderr *bytes.Buffer)
- func SilentError(err error) error
- type ErrorResponse
- type StructuredError
Constants ¶
const ( // Input: CLI flag and argument validation. ErrInputMissing = "INPUT_001" // required flag or argument not provided ErrInputConflict = "INPUT_002" // mutually exclusive flags used together ErrInputInvalid = "INPUT_003" // flag value is invalid (wrong format, out of range) ErrInputTerminal = "INPUT_004" // command requires interactive terminal )
Error code constants. Each code is namespaced by category and numbered. Format: CATEGORY_NNN
const ( ExitSuccess = 0 // Success ExitError = 1 // General error ExitUsage = 2 // Usage error (invalid arguments, missing config, etc.) ExitDrift = 3 // Drift detected (drift command only) )
Exit codes for consistent scripting behavior.
Variables ¶
Functions ¶
func AllErrorCodes ¶
func AllErrorCodes() []string
AllErrorCodes returns all registered error code values for validation. Used by tests to assert uniqueness and format correctness.
func IsSilentError ¶
IsSilentError checks if an error is marked as already printed.
func PrintError ¶
func PrintStructuredError ¶
func PrintStructuredError(e StructuredError)
PrintStructuredError prints a StructuredError to ErrWriter. In JSON mode, prints structured JSON. In plain mode, prints human-readable format.
func PrintVerbose ¶
PrintVerbose prints only when Verbose is true.
func SetForTest ¶
SetForTest saves current global state and returns test-safe writers. It registers a cleanup function via t.Cleanup to restore all globals after the test completes (even if the test panics).
Returns (stdout, stderr) buffers that are also set as Writer/ErrWriter.
func SilentError ¶
SilentError wraps an error to mark it as already printed.
Types ¶
type ErrorResponse ¶
type StructuredError ¶
type StructuredError struct {
Code string `json:"code"`
Message string `json:"message"`
Suggestion string `json:"suggestion,omitempty"`
Details string `json:"details,omitempty"`
}
StructuredError is a machine-readable error with a namespaced code.
func NewStructuredError ¶
func NewStructuredError(code, message, suggestion string) StructuredError
NewStructuredError creates a StructuredError with Code, Message, and Suggestion.
func (StructuredError) Error ¶
func (e StructuredError) Error() string
Error implements the error interface so StructuredError works with errors.As().