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 ¶
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 ¶
IsUniqueViolation reports whether err is or wraps a pgx unique constraint violation (SQLSTATE 23505).
func WrapError ¶
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.
Click to show internal directories.
Click to hide internal directories.