Grove

Errors

Sentinel errors returned by Grove operations.

Grove defines sentinel errors for all failure cases. Use errors.Is() to check for specific errors.

Query Errors

ErrorDescription
ErrNoRowsQuery returned no rows (similar to sql.ErrNoRows)
ErrModelNotRegisteredModel type was not registered via RegisterModel()
ErrNotSupportedOperation not supported by the current driver

Driver Errors

ErrorDescription
ErrDriverClosedDriver connection pool has been closed
ErrTxDoneTransaction has already been committed or rolled back
ErrInvalidDSNData source name is malformed

Migration Errors

ErrorDescription
ErrMigrationFailedA migration function returned an error
ErrMigrationLockedAnother process holds the migration lock
ErrCyclicDependencyMigration group dependencies form a cycle
ErrDuplicateVersionTwo migrations share the same version string

Hook Errors

ErrorDescription
ErrHookDeniedA privacy hook returned Decision: Deny
ErrHookPanicA hook panicked during execution (recovered)

Schema Errors

ErrorDescription
ErrInvalidTagStruct tag has invalid syntax
ErrNoPrimaryKeyModel has no field marked as pk
ErrInvalidRelationRelation definition is incomplete or incorrect

Usage

import "github.com/xraph/grove"

var users []User
err := db.NewSelect(&users).
    Where("active = $1", true).
    Scan(ctx)

if errors.Is(err, grove.ErrNoRows) {
    // No matching users found
}

if errors.Is(err, grove.ErrModelNotRegistered) {
    // Forgot to call db.RegisterModel((*User)(nil))
}

Wrapping

All errors returned by Grove wrap the underlying driver error when available:

err := db.NewSelect(&users).Scan(ctx)
if err != nil {
    // Unwrap to get the original pgx/mysql error
    var pgErr *pgconn.PgError
    if errors.As(err, &pgErr) {
        fmt.Println(pgErr.Code) // e.g., "23505" for unique violation
    }
}

On this page