errors

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package errors provides error classification for database errors.

Index

Constants

View Source
const (
	HintTableNotFound    = "Table not found. Use 'schema tables' to see available tables."
	HintColumnNotFound   = "Column not found. Use 'schema describe <table>' to see available columns."
	HintReadOnly         = "This connection is read-only. To enable writes, use a credential with writePermission and pass --write."
	HintConnectionFailed = "Cannot connect. Check that the host and port are correct and the server is running."
	HintAuthFailed       = "Authentication failed. Check the username and password."
	HintTimeout          = "Query timed out. Increase with --timeout <ms> or 'config set query.timeout <ms>'."
)

Standard hint strings used across drivers for consistent error messages.

Variables

This section is empty.

Functions

func As

func As(err error, target **QueryError) bool

As is a convenience wrapper for errors.As with QueryError.

func RegisterClassifier

func RegisterClassifier(c Classifier)

RegisterClassifier adds a classifier to the chain.

Types

type Classifier

type Classifier func(err error, ctx ErrorContext) *QueryError

Classifier is a function that attempts to classify a database error. Returns nil if the error is not recognized.

type ErrorContext

type ErrorContext struct {
	ConnectionAlias      string
	AvailableTables      []string
	AvailableConnections []string
}

ErrorContext provides context for error classification.

type FixableBy

type FixableBy string

FixableBy indicates who can fix an error.

const (
	FixableByAgent FixableBy = "agent"
	FixableByHuman FixableBy = "human"
	FixableByRetry FixableBy = "retry"
)

type QueryError

type QueryError struct {
	Message   string    `json:"error"`
	Hint      string    `json:"hint,omitempty"`
	FixableBy FixableBy `json:"fixable_by"`
	Cause     error     `json:"-"`
}

QueryError is a classified database error with context for LLMs.

func Classify

func Classify(err error, ctx ErrorContext) *QueryError

Classify attempts to classify an error using the registered classifiers. If the error already has a FixableBy field (pre-classified by a driver), it is returned as-is.

func New

func New(message string, fixableBy FixableBy) *QueryError

New creates a QueryError.

func NotFound

func NotFound(alias string, available []string) *QueryError

NotFound creates a "not found" error for connections.

func Wrap

func Wrap(err error, fixableBy FixableBy) *QueryError

Wrap creates a QueryError wrapping an underlying error.

func (*QueryError) Error

func (e *QueryError) Error() string

func (*QueryError) Unwrap

func (e *QueryError) Unwrap() error

func (*QueryError) WithHint

func (e *QueryError) WithHint(hint string) *QueryError

WithHint adds a hint to a QueryError.

Jump to

Keyboard shortcuts

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