errors

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package errors defines pgGo's stable, machine-readable error contract.

Every failure pgGo reports has exactly one Type from the fixed set below, the PostgreSQL SQLSTATE when the server supplied one, and a retryable flag, so an agent never has to infer error categories from message strings.

Index

Constants

View Source
const (
	Connection     = "connection_error"
	Authentication = "authentication_error"
	Timeout        = "timeout"
	Postgres       = "postgres_error"
	InvalidInput   = "invalid_input"
	Protocol       = "protocol_error"
)

Error types. This set is part of the public contract; do not rename.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Type      string
	Code      string // SQLSTATE; empty when not from the server
	Message   string
	Detail    string
	Hint      string
	Position  int // 1-based character position in the SQL, 0 if unknown
	Retryable bool
}

Error is the structured error emitted as {"ok":false,"error":{...}}.

func Classify

func Classify(err error) *Error

Classify converts any Go error into a structured *Error.

func FromServer

func FromServer(code, message, detail, hint string, position int) *Error

FromServer classifies a PostgreSQL ErrorResponse by SQLSTATE.

func New

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

New returns an error of the given type.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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