Documentation
¶
Overview ¶
Package errs defines gskill's typed errors and their mapping to process exit codes. Errors wrap their cause with %w so errors.Is and errors.As traverse the chain, and ExitCode resolves any error to a stable code in the range 0-12 documented in contracts/cli-commands.md.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUsage = &Error{Code: CodeUsage, Msg: "usage error"} ErrInvalidManifest = &Error{Code: CodeInvalidManifest, Msg: "invalid manifest"} ErrLockMismatch = &Error{Code: CodeLockMismatch, Msg: "lockfile mismatch"} ErrIntegrity = &Error{Code: CodeIntegrity, Msg: "integrity failure"} ErrDrift = &Error{Code: CodeDrift, Msg: "drift detected"} ErrUpdateAvailable = &Error{Code: CodeUpdateAvailable, Msg: "update available"} ErrUnsupportedAgent = &Error{Code: CodeUnsupportedAgent, Msg: "unsupported or undetected agent"} ErrPartialInstall = &Error{Code: CodePartialInstall, Msg: "partial installation"} ErrAuth = &Error{Code: CodeAuth, Msg: "authentication failure"} ErrCacheLock = &Error{Code: CodeCacheLock, Msg: "cache or lock failure"} )
Sentinel errors, one per exit code. Wrap them with %w (or Wrap) to attach context while preserving the code.
Functions ¶
func ExitCode ¶
ExitCode resolves err to its process exit code: 0 for nil, the Code of the first *Error found in the chain, or CodeGeneric (1) for any other error.
Example ¶
package main
import (
"fmt"
"github.com/glapsfun/gskill/internal/errs"
)
func main() {
// A wrapped sentinel keeps its exit code through %w wrapping.
err := fmt.Errorf("git fetch: %w", errs.ErrAuth)
fmt.Println(errs.ExitCode(err))
}
Output: 11
Example (Unknown) ¶
package main
import (
"errors"
"fmt"
"github.com/glapsfun/gskill/internal/errs"
)
func main() {
fmt.Println(errs.ExitCode(errors.New("something unexpected")))
}
Output: 1
func HintOf ¶ added in v0.2.0
HintOf returns the first non-empty hint found along err's chain, or "".
Types ¶
type Code ¶
type Code int
Code is a gskill process exit code.
const ( CodeOK Code = 0 // success CodeGeneric Code = 1 // generic/unexpected error CodeUsage Code = 2 // usage error (bad flags/args) CodeInvalidManifest Code = 3 // invalid manifest CodeLockMismatch Code = 4 // lockfile mismatch (--frozen-lockfile would change) CodeIntegrity Code = 6 // integrity failure (checksum mismatch) CodeDrift Code = 7 // drift detected (--fail-on-drift) CodeUpdateAvailable Code = 8 // update available (outdated --exit-code) CodeUnsupportedAgent Code = 9 // unsupported / undetected agent CodePartialInstall Code = 10 // partial installation CodeAuth Code = 11 // authentication failure CodeCacheLock Code = 12 // cache / lock failure (incl. lock-acquire timeout) )
Exit codes (FR-038). These are the process's external contract and must not be renumbered.
type Error ¶
Error carries a gskill exit Code and, optionally, an underlying cause that remains reachable through errors.Is, errors.As, and errors.Unwrap, plus an optional Hint: a one-line actionable next step the CLI renders after the error message ("→ run 'gskill init' to create one"). Hint never changes Error() output, code mapping, or errors.Is/As matching.