errors

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides centralized error handling for OpenPass CLI commands. It defines typed errors with exit codes and consistent error wrapping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(code ExitCode, msg string, err error) error

Wrap wraps an existing error with a message and exit code.

Types

type CLIError

type CLIError struct {
	Code    ExitCode
	Message string
	Cause   error
}

CLIError is a structured error with an exit code and user-friendly message.

func NewCLIError

func NewCLIError(code ExitCode, msg string, cause error) *CLIError

NewCLIError creates a new CLIError with the given code, message, and optional cause.

func (*CLIError) Error

func (e *CLIError) Error() string

Error implements the error interface.

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

Unwrap returns the underlying cause for errors.Is/errors.As support.

type ExitCode

type ExitCode int

ExitCode represents a process exit code for CLI commands.

const (
	// ExitSuccess indicates successful completion.
	ExitSuccess ExitCode = 0
	// ExitGeneralError indicates a general error.
	ExitGeneralError ExitCode = 1
	// ExitUsageError indicates a command-line usage error.
	ExitUsageError ExitCode = 2
	// ExitVaultLocked indicates the vault is locked or passphrase is missing.
	ExitVaultLocked ExitCode = 3
	// ExitNotInitialized indicates the vault is not initialized.
	ExitNotInitialized ExitCode = 4
	// ExitMCPError indicates an MCP server error.
	ExitMCPError ExitCode = 5
)

func ExitCodeFromError

func ExitCodeFromError(err error) ExitCode

ExitCodeFromError extracts the exit code from an error. If the error is a *CLIError, it returns the embedded code. Otherwise, it returns ExitGeneralError.

Jump to

Keyboard shortcuts

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