errors

package
v0.1.1-alpha.1 Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides structured error types, error codes, and exit codes for xsql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code is a stable error code (string) for AI/agent and programmatic consumption. Codes are append-only; existing meanings must not be changed or reused.

const (
	// Config / args
	CodeCfgNotFound    Code = "XSQL_CFG_NOT_FOUND"
	CodeCfgInvalid     Code = "XSQL_CFG_INVALID"
	CodeSecretNotFound Code = "XSQL_SECRET_NOT_FOUND"

	// SSH
	CodeSSHAuthFailed      Code = "XSQL_SSH_AUTH_FAILED"
	CodeSSHHostKeyMismatch Code = "XSQL_SSH_HOSTKEY_MISMATCH"
	CodeSSHDialFailed      Code = "XSQL_SSH_DIAL_FAILED"

	// DB
	CodeDBDriverUnsupported Code = "XSQL_DB_DRIVER_UNSUPPORTED"
	CodeDBConnectFailed     Code = "XSQL_DB_CONNECT_FAILED"
	CodeDBAuthFailed        Code = "XSQL_DB_AUTH_FAILED"
	CodeDBExecFailed        Code = "XSQL_DB_EXEC_FAILED"

	// Read-only policy
	CodeROBlocked Code = "XSQL_RO_BLOCKED"

	// Port
	CodePortInUse Code = "XSQL_PORT_IN_USE"

	// Internal
	CodeInternal Code = "XSQL_INTERNAL"
)

func AllCodes

func AllCodes() []Code

type ExitCode

type ExitCode int

ExitCode represents process exit codes (stable contract); see docs/error-contract.md.

const (
	ExitOK ExitCode = 0

	// 2: argument/configuration error
	ExitConfig ExitCode = 2

	// 3: connection error (DB/SSH)
	ExitConnect ExitCode = 3

	// 4: read-only policy blocked a write
	ExitReadOnly ExitCode = 4

	// 5: DB execution error
	ExitDBExec ExitCode = 5

	// 10: internal error
	ExitInternal ExitCode = 10
)

func ExitCodeFor

func ExitCodeFor(code Code) ExitCode

type XError

type XError struct {
	Code    Code           `json:"code" yaml:"code"`
	Message string         `json:"message" yaml:"message"`
	Details map[string]any `json:"details,omitempty" yaml:"details,omitempty"`
	// contains filtered or unexported fields
}

XError is a structured error that conforms to docs/error-contract.md.

func As

func As(err error) (*XError, bool)

func AsOrWrap added in v0.0.4

func AsOrWrap(err error) *XError

func New

func New(code Code, message string, details map[string]any) *XError

func Wrap

func Wrap(code Code, message string, details map[string]any, cause error) *XError

func (*XError) Error

func (e *XError) Error() string

func (*XError) Unwrap

func (e *XError) Unwrap() error

Jump to

Keyboard shortcuts

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