Documentation
¶
Overview ¶
Package errors is the exit-code contract shared by gotools packages: an error that carries the process exit code and the message for stderr.
Only the top-level entry point turns an Error into an exit; every other layer returns it. The codes are documented for users in the help text and docs/USAGE.md.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Table = []Doc{ {OK, "Success", "Everything worked", "Proceed"}, {Generic, "Generic failure", "Something went wrong (catch-all)", "Fail the build"}, {Usage, "Usage error", "Bad flags, wrong args, invalid input", "Fail the build (no retry)"}, {Network, "Network error", "Proxy unreachable, DNS failure, timeout", "Retry with backoff"}, {Lock, "Lock contention", "Another gotools process holds the lock", "Wait and retry"}, {ToolNotFound, "Tool not found", "Requested tool isn't installed", "Run `gotools sync` and retry"}, {Offline, "Offline required", "Network needed but `--offline` set", "Run `gotools sync` locally"}, {Policy, "Policy violation", "Tool banned, version not pinned, vuln found", "Block merge"}, {Environment, "Environment error", "Go missing/too old, bad manifest schema", "Fix environment"}, }
Table is the user-facing exit-code table, in code order. The help text is built from it, so it cannot drift from the codes.
Functions ¶
This section is empty.
Types ¶
type Code ¶
type Code int
Code is a process exit code.
func CodeOf ¶
CodeOf returns the exit code for err: OK for nil, the carried code for an *Error anywhere in the chain, Generic otherwise.
Example ¶
Callers pick the exit code with CodeOf wherever the error surfaced.
package main
import (
"fmt"
ierrors "github.com/piusalfred/gotools/internal/errors"
)
func main() {
err := fmt.Errorf("install: %w", ierrors.New(ierrors.Offline, "offline mode forbids network access"))
fmt.Println(ierrors.CodeOf(err))
fmt.Println(err)
}
Output: 6 install: offline mode forbids network access
type Error ¶
Error carries an exit code and the message for stderr. Err, when set, is the underlying cause and is reachable through errors.Is and errors.As.