sqlerr

package
v0.18.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package sqlerr carries a PostgreSQL SQLSTATE alongside an error message.

Wadjet speaks the PostgreSQL wire protocol, and a client branches on the SQLSTATE it is handed: 42P01 sends it to re-resolve a table name, 42703 to re-resolve a column, 22012 to report a data error. Before this package every failure crossed the wire as the blanket class 42000 (#366), because the planner and engine produced plain errors and the pgwire layer had nothing to extract a code from.

An error created here travels through ordinary %w wrapping; the pgwire layer recovers the code with StateOf. Errors defined elsewhere can participate without importing this package by implementing the Coder interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateOf

func StateOf(err error) string

StateOf returns the SQLSTATE carried by err or anything it wraps, or "" when none is found. The outermost carrier in the wrap chain wins.

func Wrap

func Wrap(code string, err error) error

Wrap attaches a SQLSTATE to an existing error without disturbing its chain: the result unwraps to err, so errors.Is/As against the original still hold.

Types

type Coder

type Coder interface {
	SQLState() string
}

Coder is implemented by error types that know their own SQLSTATE but do not depend on this package (e.g. expr.UnknownFuncError).

type Error

type Error struct {
	Code    string // five-character SQLSTATE, e.g. "42P01"
	Message string
}

Error is an error with a PostgreSQL SQLSTATE code.

func New

func New(code, format string, args ...any) *Error

New builds an Error with the given SQLSTATE and formatted message.

func (*Error) Error

func (e *Error) Error() string

func (*Error) SQLState

func (e *Error) SQLState() string

SQLState returns the code; Error participates in StateOf through the same Coder interface as foreign error types, so the OUTERMOST code in a wrap chain always wins regardless of which type carries it.

Jump to

Keyboard shortcuts

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