errors

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package errors provides error wrapping utilities for pgx database operations.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested record does not exist.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError reports whether err is or wraps ErrNotFound.

Example
package main

import (
	"fmt"

	axerrors "github.com/benaskins/axon-base/errors"
)

func main() {
	wrapped := axerrors.WrapError("users.Get", axerrors.ErrNotFound)
	fmt.Println(axerrors.IsNotFoundError(wrapped))
}
Output:
true
Example (False)
package main

import (
	"fmt"

	axerrors "github.com/benaskins/axon-base/errors"
)

func main() {
	err := fmt.Errorf("some other error")
	fmt.Println(axerrors.IsNotFoundError(err))
}
Output:
false

func IsUniqueViolation

func IsUniqueViolation(err error) bool

IsUniqueViolation reports whether err is or wraps a pgx unique constraint violation (SQLSTATE 23505).

func WrapError

func WrapError(op string, err error) error

WrapError wraps err with the given operation context. Returns nil if err is nil.

Example
package main

import (
	"fmt"

	axerrors "github.com/benaskins/axon-base/errors"
)

func main() {
	err := axerrors.WrapError("users.Create", fmt.Errorf("duplicate key"))
	fmt.Println(err)
}
Output:
users.Create: duplicate key
Example (Nil)
package main

import (
	"fmt"

	axerrors "github.com/benaskins/axon-base/errors"
)

func main() {
	err := axerrors.WrapError("users.Create", nil)
	fmt.Println(err)
}
Output:
<nil>

Types

This section is empty.

Jump to

Keyboard shortcuts

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