errors

package
v0.1.1-beta24 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCode

func GetCode(err error) (code codes.Code)

GetCode returns the Postgres error code inside the given error. If no error code is found a Uncategorized error code returned.

func GetConstraintName

func GetConstraintName(err error) string

GetConstraintName returns the Postgres error constraint name inside the given error.

func WithCode

func WithCode(err error, code codes.Code) error

WithCode decorates the error with a Postgres error code

func WithConstraintName

func WithConstraintName(err error, constraint string) error

WithConstraintName decorates the error with a Postgres error constraint

func WithSeverity

func WithSeverity(err error, severity Severity) error

WithSeverity decorates the error with a Postgres error severity

Types

type Error

type Error struct {
	Code           codes.Code
	Message        string
	Detail         string
	Hint           string
	Severity       Severity
	ConstraintName string
	Source         *Source
}

Error contains all Postgres wire protocol error fields. See https://www.postgresql.org/docs/current/static/protocol-error-fields.html for a list of all Postgres error fields, most of which are optional and can be used to provide auxiliary error information.

func Flatten

func Flatten(err error) Error

Flatten returns a flattened error which could be used to construct Postgres wire error messages.

type Severity

type Severity string

Severity represents the severity of a thrown error. The possible error severities are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message)

const (
	LevelError   Severity = "ERROR"
	LevelFatal   Severity = "FATAL"
	LevelPanic   Severity = "PANIC"
	LevelWarning Severity = "WARNING"
	LevelNotice  Severity = "NOTICE"
	LevelDebug   Severity = "DEBUG"
	LevelInfo    Severity = "INFO"
	LevelLog     Severity = "LOG"
)

Represents the severity of a thrown error. The possible error severities are ERROR, FATAL, or PANIC (in an error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message)

func DefaultSeverity

func DefaultSeverity(severity Severity) Severity

DefaultSeverity returns the default severity (ERROR) if no valid severity has been defined.

func GetSeverity

func GetSeverity(err error) Severity

GetSeverity returns the Postgres error severity inside the given error.

type Source

type Source struct {
	File     string
	Line     int32
	Function string
}

Source represents whenever possible the source of a given error.

Jump to

Keyboard shortcuts

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