Skip to Content
fusion-orm
API Reference

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

SentinelTriggerNotes
fusion.ErrRecordNotFoundFirst/Take/Last when no row matches.Alias of logger.ErrRecordNotFound. Find returns an empty slice instead of this error.
fusion.ErrMissingWhereClauseGlobal Update/Delete without WHERE conditions.Relaxed by Config.AllowGlobalUpdate.
fusion.ErrDuplicatedKeyDriver constraint error, translated.Alias of dialect.ErrDuplicatedKey.
fusion.ErrForeignKeyViolatedDriver constraint error, translated.Alias of dialect.ErrForeignKeyViolated.
fusion.ErrCheckConstraintViolatedDriver constraint error, translated.Alias of dialect.ErrCheckConstraintViolated.
fusion.ErrInvalidValueDestination or argument of the wrong type (e.g. Find on a non-pointer).A programmer error.
fusion.ErrInvalidTransactionCommit/Rollback outside a transaction.
fusion.ErrUnsupportedFeatureThe active dialect lacks a feature flag required by the operation.The message names the feature (see UnsupportedFeatureError).
fusion.ErrDryRunModeUnsupportedA finisher that requires execution is used while Config.DryRun is set.
fusion.ErrRegisteredUse when a plugin name is already taken.
fusion.ErrInvalidDBThe underlying connection pool cannot be resolved to a *sql.DB.
fusion.ErrInvalidModelNon-struct model passed to parse.Alias of schema.ErrInvalidModel.
fusion.ErrInvalidTagUnknown or malformed fusion tag (strict mode).Alias of schema.ErrInvalidTag.
fusion.ErrAmbiguousFieldTwo fields resolving to the same column.Alias of schema.ErrAmbiguousField.
fusion.ErrInvalidRelationMalformed 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) error

UnsupportedFeatureError.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

SentinelTrigger
fusion.ErrDuplicateCallbackA callback name is already used in the same processor (from Register).
fusion.ErrCallbackNotFoundReplace/Remove/Before/After with an anchor name that is not registered.
fusion.ErrCallbackPanicA callback panic is recorded on db.Error so the chain's finalizers release the transaction before the panic is re-thrown.

dialect package sentinels

SentinelTrigger
dialect.ErrDuplicatedKeyduplicated key not allowed — produced by dialect error translators.
dialect.ErrForeignKeyViolatedviolates foreign key constraint — produced by dialect error translators.
dialect.ErrCheckConstraintViolatedviolates check constraint — produced by dialect error translators.
SentinelTrigger
dialect.ErrStringNULA 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

SentinelTrigger
migrator.ErrUnsupportedFeatureThe dialect lacks a capability required by a migration operation; wrapped with the missing feature's name.

logger package sentinels

SentinelTrigger
logger.ErrRecordNotFoundThe "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

On this page