Documentation
¶
Overview ¶
Package kerrors defines kraai's error types. KError wraps a cause built with cockroachdb/errors, so a stack is always captured, and tags it with a Code that maps to a fixed process exit code. Only cmd/kraai inspects the exit code, decides whether to print the stack, and exits.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExitCode ¶
ExitCode maps err to a process exit code: 0 for nil, the *KError's own code when one is anywhere in the chain, and CodeUnexpected's otherwise.
func Wrap ¶
Wrap wraps cause as a *KError with a formatted message and code, for a failure that originated outside kraai. A nil cause returns nil.
Wrap returns error, not *KError, so that nil is a true nil interface rather than a typed nil whose methods panic. The other constructors never return nil and keep *KError, so callers reach Code without an assertion.
Types ¶
type Code ¶
type Code int
Code identifies a kraai error's failure category. Each Code has a fixed ExitCode; the table is small and CI-branchable on purpose.
const ( // CodeUnexpected is the fallback bucket, including any error that is // not a *KError at all. CodeUnexpected Code = 1 // CodeValidation marks a manifest, input or config validation failure. CodeValidation Code = 2 // CodeLockHeld marks an environment lock another operation holds. CodeLockHeld Code = 3 // CodeConfirmationRequired marks a protected operation whose required // confirmation was missing or did not match. CodeConfirmationRequired Code = 4 )
Values are explicit, not iota-derived: the exit-code table is a public CI contract, so inserting a Code must never shift a downstream exit code.
type KError ¶
type KError struct {
// contains filtered or unexported fields
}
KError is kraai's base error type. Build one with New, Wrap or a typed constructor, never a struct literal, since the cause must be constructed through cockroachdb/errors to capture a stack.
func ConfirmationRequired ¶
ConfirmationRequired creates a *KError in the CodeConfirmationRequired bucket.
func New ¶
New creates a *KError in the CodeUnexpected bucket with a formatted message. Use a typed constructor when the failure fits a specific bucket.
func Validation ¶
Validation creates a *KError in the CodeValidation bucket.