fediglam/src/sql/errors.zig

95 lines
2.9 KiB
Zig
Raw Normal View History

2022-10-01 09:05:33 +00:00
const std = @import("std");
// Error for any miscellaneous or unexpected error codes
const UnexpectedError = error{Unexpected};
// Errors related to database connections, common to (most) api calls
const ConnectionError = error{
// The operation was cancelled by the user
Cancelled,
// The database connection could not be created or was lost
BadConnection,
// An internal error occurred in the engine.
// Examples include:
// - Out of Memory
// - Filesystem full
// - Unknown crash
// - Filesystem permissions denied
2022-10-04 02:41:59 +00:00
InternalException,
2022-10-01 09:05:33 +00:00
};
// Errors related to constraint validation
const ConstraintError = error{
// A `NOT NULL` constraint was violated
NotNullViolation,
// A `FOREIGN KEY` constraint was violated
ForeignKeyViolation,
// A `UNIQUE` constraint was violated
UniqueViolation,
// A `CHECK` constraint was violated
CheckViolation,
// A unknown constraint type was violated
ConstraintViolation,
};
// Errors related to argument binding
const ArgumentError = error{
// One of the arguments passed could not be marshalled to pass to the SQL engine
2022-10-04 02:41:59 +00:00
BindException,
2022-10-01 09:05:33 +00:00
// The set of arguments passed did not map to query parameters
2022-10-04 02:41:59 +00:00
UnusedArgument,
2022-10-01 09:05:33 +00:00
// The allocator used for staging the query ran out of memory
OutOfMemory,
2022-10-04 02:41:59 +00:00
AllocatorRequired,
2022-10-01 09:05:33 +00:00
};
// Errors related to retrieving query result columns
const ResultColumnError = error{
// The allocator used for retrieving the results ran out of memory
OutOfMemory,
2022-10-04 02:41:59 +00:00
AllocatorRequired,
2022-10-01 09:05:33 +00:00
// A type error occurred when parsing results (means invalid data is in the DB)
ResultTypeMismatch,
};
// Errors related to executing SQL queries
const StartQueryError = error{
// The database is locked by another query and the timeout was exceeded
DatabaseBusy,
// Access to one or more resources was denied
PermissionDenied,
// The SQL query had invalid syntax or used an invalid identifier
2022-10-04 02:41:59 +00:00
SqlException,
2022-10-01 09:05:33 +00:00
// The set of columns to parse did not match the columns returned by the query
ColumnMismatch,
// Either an explicit transaction was open and a query method was called on the DB directly,
// or no explicit transaction was open and a query method was called on a transaction;
BadTransactionState,
};
pub const library_errors = struct {
const BaseError = ConnectionError || UnexpectedError;
// TODO: clean this up
pub const OpenError = BaseError;
pub const QueryError = BaseError || ArgumentError || ConstraintError || StartQueryError;
pub const RowError = BaseError || ResultColumnError || ConstraintError || StartQueryError;
2022-10-04 02:41:59 +00:00
pub const QueryRowError = QueryError || RowError || error{ NoRows, TooManyRows };
pub const ExecError = QueryError;
2022-10-01 09:05:33 +00:00
pub const BeginError = BaseError || StartQueryError;
pub const CommitError = BaseError || StartQueryError || ConstraintError;
};