errors

package
v0.0.0-...-d57b50c Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 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 GetDetail

func GetDetail(err error) string

GetDetail returns the Postgres detail inside the given error. If no error detail is an empty string returned.

func GetHint

func GetHint(err error) string

GetHint returns the Postgres hint inside the given error. If no error hint is an empty string returned.

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 WithDetail

func WithDetail(err error, detail string) error

WithDetail decorates the error with Postgres error details

func WithHint

func WithHint(err error, hint string) error

WithHint decorates the error with a Postgres error hint

func WithSeverity

func WithSeverity(err error, severity Severity) error

WithSeverity decorates the error with a Postgres error severity

func WithSource

func WithSource(err error, file string, line int32, function string) error

WithSource decorates the error with a Postgres error source

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.

func GetSource

func GetSource(err error) *Source

GetSource returns the Postgres source inside the given error. If no error hint is an empty string returned.

Jump to

Keyboard shortcuts

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