errors

package
v0.2.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package errors provides CLI error handling utilities that map API errors to user-friendly messages and appropriate exit codes.

Exit codes follow POSIX conventions with extensions for specific error types:

0 - Success
1 - General error
2 - Misuse (invalid arguments, configuration)
3 - Authentication required
4 - Permission denied
5 - Resource not found
6 - Rate limited
7 - Server error

Usage:

if err := doSomething(); err != nil {
    code := errors.HandleError(err)
    os.Exit(code)
}

Index

Constants

View Source
const (
	// ExitSuccess indicates successful completion.
	ExitSuccess = 0

	// ExitError indicates a general error occurred.
	ExitError = 1

	// ExitMisuse indicates command line misuse (invalid arguments, bad config).
	ExitMisuse = 2

	// ExitAuth indicates authentication is required or credentials are invalid.
	ExitAuth = 3

	// ExitForbidden indicates permission was denied for the operation.
	ExitForbidden = 4

	// ExitNotFound indicates the requested resource was not found.
	ExitNotFound = 5

	// ExitRateLimited indicates the request was rate limited.
	ExitRateLimited = 6

	// ExitServerError indicates a server-side error occurred.
	ExitServerError = 7

	// ExitNetwork indicates a network connectivity error.
	ExitNetwork = 8

	// ExitTimeout indicates the operation timed out.
	ExitTimeout = 9

	// ExitPlanLimit indicates a plan limit was exceeded.
	ExitPlanLimit = 10
)

Exit codes for CLI operations. These follow POSIX conventions with extensions for StackEye-specific errors.

Variables

This section is empty.

Functions

func ExitCodeName

func ExitCodeName(code int) string

ExitCodeName returns a human-readable name for an exit code. Useful for logging and debugging.

func HandleError

func HandleError(err error) int

HandleError processes an error, prints a user-friendly message to stderr, and returns the appropriate exit code.

If err is nil, returns ExitSuccess (0).

The function handles these error types:

  • *client.APIError: Maps API errors to appropriate exit codes and messages
  • Network errors: Connection refused, DNS failures, timeouts
  • Context errors: Deadline exceeded, canceled
  • Generic errors: Returns ExitError with the error message

func SetErrWriter

func SetErrWriter(w io.Writer)

SetErrWriter sets the writer for error output. Used for testing.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL