error.rs

Overview

This file defines error handling constructs for interfacing with SQLite, encapsulating SQLite error codes and extended error codes into Rust-friendly types and messages. It provides an ErrorCode enumeration that represents various SQLite error conditions, an Error struct that holds both a primary error code and an extended error code, and utility functions for mapping numeric SQLite error codes to human-readable descriptions. Additionally, it optionally defines an InitError enumeration for loadable extension initialization errors, conditional on the loadable_extension feature.

The file's primary purpose is to convert raw SQLite error codes into strongly-typed Rust errors with descriptive messages, facilitating robust error management in database operations.


Enumerations and Structs

ErrorCode

An enum representing the canonical set of SQLite error codes.

Error

A struct that represents a SQLite error, combining the main error code and the extended error code.


Functions

code_to_str

pub fn code_to_str(code: c_int) -> &'static str

Maps an SQLite raw error code (including extended codes) to a static string description.

let description = code_to_str(sqlite_code);
println!("Error description: {}", description);

Loadable Extension Error Handling (Feature-gated)

InitError

Defined only if the loadable_extension feature is enabled.

An enum representing errors during loadable SQLite extension initialization.


Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram: Error Handling Structure

classDiagram
class ErrorCode {
<<enum>>
+InternalMalfunction
+PermissionDenied
+OperationAborted
+DatabaseBusy
+DatabaseLocked
+OutOfMemory
+ReadOnly
+OperationInterrupted
+SystemIoFailure
+DatabaseCorrupt
+NotFound
+DiskFull
+CannotOpen
+FileLockingProtocolFailed
+SchemaChanged
+TooBig
+ConstraintViolation
+TypeMismatch
+ApiMisuse
+NoLargeFileSupport
+AuthorizationForStatementDenied
+ParameterOutOfRange
+NotADatabase
+Unknown
}
class Error {
+code: ErrorCode
+extended_code: c_int
+new()
+fmt::Display
+error::Error
}
class InitError {
<<enum>>
+VersionMismatch
+NullFunctionPointer
+fmt::Display
+error::Error
}
Error --> ErrorCode : has
Error ..> "code_to_str()" : uses
InitError <|-- (feature: loadable_extension)

Testing


Key References