NAME
DBIx::Fast::X - Typed exceptions for DBIx::Fast
SYNOPSIS
use v5.38;
eval { $db->insert('users', { email => $email }) };
if ($@ isa DBIx::Fast::X::Duplicate) {
warn "already registered (key: ", $@->constraint, ")";
}
elsif ($@ isa DBIx::Fast::X::DB) {
warn "database error ", $@->code, " / ", $@->state, " in: ", $@->sql;
}
elsif ($@) { die $@ }
DESCRIPTION
Everything DBIx::Fast throws is an object of one of these classes. Each one stringifies to exactly the message a plain string exception carried (including the at FILE line N. suffix), so existing code that matches $@ with a regex, prints it or logs it keeps working unchanged.
Database errors are only thrown when the handle raises them (RaiseError, the default), or by the methods that always throw (the CRUD writers, strict_reads).
CLASSES
DBIx::Fast::X base: message, error, TO_JSON
+- DBIx::Fast::X::Usage validation / usage errors (bad identifier,
| invalid operator, missing argument, ...)
`- DBIx::Fast::X::DB database errors: code, state, driver, sql,
| binds, constraint
+- ::Duplicate unique / primary key violation
+- ::ForeignKey foreign key violation
+- ::NotNull NOT NULL violation
+- ::Deadlock deadlock / serialization failure
+- ::LockTimeout lock wait timeout / database busy
+- ::Syntax SQL syntax error
`- ::Connection connection lost / refused
Classification uses the driver error code (MariaDB/MySQL), the SQLSTATE (PostgreSQL) or SQLite's fixed constraint messages - never user data.
METHODS
message
The full text (what the object stringifies to).
error
The bare driver or validation message, without prefixes or location.
code, state, driver
Driver error code ($DBI::err), SQLSTATE and driver name (DBIx::Fast::X::DB and subclasses).
sql, binds
The statement in flight and its bind values (binds are '<redacted>' under errors_redact).
constraint
The violated key / constraint name when the driver message carries it (MariaDB/MySQL for key 'x', Pg constraint "x", SQLite table.column).
TO_JSON
Returns the message, so JSON encoders serialize the exception as text.
throw
DBIx::Fast::X::Usage->throw(message => ..., error => ...);
class_for, constraint_from
Classification helpers used internally (class methods).
SEE ALSO
DBIx::Fast, "Exception" in DBIx::Fast, "RaiseError" in DBI, "HandleError" in DBI
AUTHOR
SeHarrys
LICENSE
This is free software under the Artistic License 2.0.