errors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code 是稳定错误码(字符串),供 AI/agent 与程序判断。 只增不改、不复用旧含义。

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"

	// Internal
	CodeInternal Code = "XSQL_INTERNAL"
)

func AllCodes

func AllCodes() []Code

type ExitCode

type ExitCode int

ExitCode 是进程退出码(稳定契约);详见 docs/error-contract.md。

const (
	ExitOK ExitCode = 0

	// 2: 参数/配置错误
	ExitConfig ExitCode = 2

	// 3: 连接错误(DB/SSH)
	ExitConnect ExitCode = 3

	// 4: 只读策略拦截写入
	ExitReadOnly ExitCode = 4

	// 5: DB 执行错误
	ExitDBExec ExitCode = 5

	// 10: 内部错误
	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 是结构化错误,满足 docs/error-contract.md。

func As

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

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