Error sentinels
Every errors.Is-compatible sentinel across fusion, dialect, migrator, schema, callbacks, and logger.
Every branchable failure in fusion-orm is an errors.Is-compatible
sentinel. Never string-match these. Sentinels are defined in their
natural package and aliased by the root package so callers usually only
import fusion.
How errors accumulate: AddError
// AddError records err on db's single error slot using wrap-chain
// semantics: the first error is kept as the wrap head so errors.Is continues
// to match it, and subsequent errors are appended with "; %w" so every cause
// stays branchable.When Config.TranslateError is set and the dialector implements
ErrorTranslator, the error is translated before being recorded. A
finisher never panics for user errors — check res.Error with
errors.Is.
fusion package sentinels
| Sentinel | Trigger | Notes |
|---|---|---|
fusion.ErrRecordNotFound | First/Take/Last when no row matches. | Alias of logger.ErrRecordNotFound. Find returns an empty slice instead of this error. |
fusion.ErrMissingWhereClause | Global Update/Delete without WHERE conditions. | Relaxed by Config.AllowGlobalUpdate. |
fusion.ErrDuplicatedKey | Driver constraint error, translated. | Alias of dialect.ErrDuplicatedKey. |
fusion.ErrForeignKeyViolated | Driver constraint error, translated. | Alias of dialect.ErrForeignKeyViolated. |
fusion.ErrCheckConstraintViolated | Driver constraint error, translated. | Alias of dialect.ErrCheckConstraintViolated. |
fusion.ErrInvalidValue | Destination or argument of the wrong type (e.g. Find on a non-pointer). | A programmer error. |
fusion.ErrInvalidTransaction | Commit/Rollback outside a transaction. | |
fusion.ErrUnsupportedFeature | The active dialect lacks a feature flag required by the operation. | The message names the feature (see UnsupportedFeatureError). |
fusion.ErrDryRunModeUnsupported | A finisher that requires execution is used while Config.DryRun is set. | |
fusion.ErrRegistered | Use when a plugin name is already taken. | |
fusion.ErrInvalidDB | The underlying connection pool cannot be resolved to a *sql.DB. | |
fusion.ErrInvalidModel | Non-struct model passed to parse. | Alias of schema.ErrInvalidModel. |
fusion.ErrInvalidTag | Unknown or malformed fusion tag (strict mode). | Alias of schema.ErrInvalidTag. |
fusion.ErrAmbiguousField | Two fields resolving to the same column. | Alias of schema.ErrAmbiguousField. |
fusion.ErrInvalidRelation | Malformed or unresolvable relation tag. | Alias of schema.ErrInvalidRelation. |
UnsupportedFeatureError
type UnsupportedFeatureError struct {
Feature string
}
// NewUnsupportedFeatureError returns an error that matches
// ErrUnsupportedFeature and names the missing feature.
func NewUnsupportedFeatureError(feature string) errorUnsupportedFeatureError.Unwrap() returns ErrUnsupportedFeature, so
callers branch on the sentinel while still seeing which feature was
required — e.g. RowValues in composite-key FindInBatches.
callback package sentinels
| Sentinel | Trigger |
|---|---|
fusion.ErrDuplicateCallback | A callback name is already used in the same processor (from Register). |
fusion.ErrCallbackNotFound | Replace/Remove/Before/After with an anchor name that is not registered. |
fusion.ErrCallbackPanic | A callback panic is recorded on db.Error so the chain's finalizers release the transaction before the panic is re-thrown. |
dialect package sentinels
| Sentinel | Trigger |
|---|---|
dialect.ErrDuplicatedKey | duplicated key not allowed — produced by dialect error translators. |
dialect.ErrForeignKeyViolated | violates foreign key constraint — produced by dialect error translators. |
dialect.ErrCheckConstraintViolated | violates check constraint — produced by dialect error translators. |
| Sentinel | Trigger |
|---|---|
dialect.ErrStringNUL | A string value contains a NUL byte (0x00). Silently stripping it would store a value different from the one the caller supplied; PostgreSQL rejects NUL in text outright. |
migrator package sentinels
| Sentinel | Trigger |
|---|---|
migrator.ErrUnsupportedFeature | The dialect lacks a capability required by a migration operation; wrapped with the missing feature's name. |
logger package sentinels
| Sentinel | Trigger |
|---|---|
logger.ErrRecordNotFound | The "no row matched" sentinel. The root package aliases it as fusion.ErrRecordNotFound so callers branch on a single value. Loggers also use it to skip IgnoreRecordNotFoundError noise. |
One import, one comparison
Prefer the fusion.Err… aliases — they are the same error values, so
errors.Is(err, fusion.ErrDuplicatedKey) matches errors produced by the
dialect translator with zero extra imports.
Next
Clause types
The clause.Interface contract, every clause struct with its Name() string, the canonical build order, and golden renderings.
Schema & naming symbols
The metadata layer plugins and advanced users touch — Table, Field, Relation, namers, appenders, scanners, and serializers from package schema.