Class DbErrorClassifier

Namespace: redb.Core.Data
Assembly: redb.Core.dll

Classifies provider exceptions by their native error code without referencing the drivers.

One place for every duck-typed code check. Before this type there were two independent copies of
the same reflection walk — DeadlockRetryHelper.IsDeadlock and
RedbServiceBase.IsUndefinedFunctionError — and V4 needed a third (insufficient privilege)
and a fourth (unique violation). Four copies of "walk the inner-exception chain, read
SqlState or Number by reflection" is how one of them ends up subtly different.


Reflection rather than a driver reference on purpose: redb.Core must not depend on Npgsql,
Microsoft.Data.SqlClient or Microsoft.Data.Sqlite. The property names (SqlState,
Number, SqliteErrorCode, SqliteExtendedErrorCode) are the drivers' public
API and have been stable for years.

public static class DbErrorClassifier

Inheritance

Object→DbErrorClassifier

Methods

DescribeUniqueViolation(Exception)

What the driver said about a unique violation: the constraint or index name, its own detail

public static (string? ConstraintName, string? Detail, long? StructureId, RedbUniqueViolationKind Kind) DescribeUniqueViolation(Exception ex)

IsDeadlock(Exception)

SQL Server 1205, PostgreSQL 40P01. The retry helper's condition.

public static bool IsDeadlock(Exception ex)

IsInsufficientPrivilege(Exception)

The connected role is not allowed to do what the statement does: PostgreSQL 42501

public static bool IsInsufficientPrivilege(Exception ex)

IsSerializationFailure(Exception)

PostgreSQL 40001 (serialization_failure), SQL Server 3960/3961 (snapshot update conflict).

public static bool IsSerializationFailure(Exception ex)

IsUndefinedFunction(Exception)

The function or procedure named in the statement does not exist: PostgreSQL 42883, SQL Server

public static bool IsUndefinedFunction(Exception ex)

IsUniqueViolation(Exception)

A unique index or constraint rejected the row: PostgreSQL 23505, SQL Server 2601 (unique

public static bool IsUniqueViolation(Exception ex)