Documentation
¶
Index ¶
- Constants
- func IsManagedBy(annotations map[string]string) bool
- type Error
- func (e *Error) Error() string
- func (e *Error) ExitCode() int
- func (e *Error) Unwrap() error
- func (e *Error) WithAvailable(items ...string) *Error
- func (e *Error) WithContext(key, value string) *Error
- func (e *Error) WithExitCode(code int) *Error
- func (e *Error) WithSuggestions(suggestions ...string) *Error
Constants ¶
const ( ManagedByAnnotation = "app.kubernetes.io/managed-by" Name = "nctl" )
const ( // ExitOK indicates that the program exited successfully. ExitOK = 0 // ExitError indicates that the program exited unsuccessfully // but gives no extra context as to what the failure was. ExitError = 1 // ExitUsageError indicates that the program exited unsuccessfully // because it was used incorrectly. // // Examples: a required argument was omitted or an invalid value // was supplied for a flag. ExitUsageError = 80 // ExitForbidden indicates that the program exited unsuccessfully // because the user isn't authorized to perform the requested action. ExitForbidden = 83 // ExitInternalError indicates that the program exited unsuccessfully // because of a problem in its own code. // // Used instead of 1 when the problem is known to be with the program's // code or dependencies. ExitInternalError = 100 // because a service it depends on was not available. // // Examples: A local daemon or remote service did not respond, a connection // was closed unexpectedly, an HTTP service responded with 503. ExitUnavailable = 101 )
Exit codes following the square/exit convention. See https://pkg.go.dev/github.com/square/exit#readme-the-codes for details.
Variables ¶
This section is empty.
Functions ¶
func IsManagedBy ¶
Types ¶
type Error ¶
type Error struct {
// Err is the underlying error being wrapped.
Err error
// Code is the exit code for this error. When zero, ExitCode defaults to ExitError (1).
Code int
// Context provides additional key-value metadata about the error (e.g., "Organization": "foo").
Context map[string]string
// Available lists valid options that could have been used.
Available []string
// Suggestions provides recommended commands or actions to fix the error.
Suggestions []string
}
Error wraps an error with additional context for user-friendly display. It implements [kong.ExitCoder] to provide semantic exit codes.
func ErrorWithContext ¶
ErrorWithContext wraps an existing error with contextual information. Returns nil if err is nil.
func (*Error) Error ¶
Error returns the full formatted error for display to the user, including context, available options, and suggestions.
func (*Error) ExitCode ¶
ExitCode returns the exit code for this error, satisfying [kong.ExitCoder]. When Code is zero, it defaults to ExitError (1).
func (*Error) WithAvailable ¶
WithAvailable adds available options to the error.
func (*Error) WithContext ¶
WithContext adds a key-value pair to the error context.
func (*Error) WithExitCode ¶
WithExitCode sets the exit code for the error.
func (*Error) WithSuggestions ¶
WithSuggestions adds suggested actions to the error.