Expand description
Contains enum with error definitions Defines the custom error type for all database-related operations.
This module centralizes error handling for the entire database layer by providing a
single, comprehensive enum, SqlInterfaceError. By using the thiserror crate,
it automatically derives the std::error::Error trait and generates clear,
user-friendly Display implementations for each error variant.
§Key Features
-
Centralized Error Handling: All potential failures within the
sql_interfaceand its submodules are codified here. This creates a single source of truth for what can go wrong with database interactions. -
Rich Context: Most error variants capture valuable context, such as
location: The module path where the error occurred, provided bymodule_path!().query: The specific SQL query string that failed.- Other relevant parameters (e.g.,
pump_id, version numbers). This makes debugging significantly easier by pinpointing the exact location and cause of a failure.
-
Error Chaining: The
#[source]attribute is used to wrap the underlying error (e.g., amysql::Errororchrono::ParseError), preserving the original error chain for in-depth analysis. -
Clarity and Specificity: Instead of generic “query failed” errors, this enum provides specific variants for different failure modes, such as
WaitTimeoutTooLow,RequiredTablesNotExisting, orSingleStringRequestNoSingleResponse.
§Error Categories
The errors can be grouped into several logical categories:
- Connection and Pool Errors: Failures related to establishing or maintaining a
connection (e.g.,
ConnectionPoolFailure,ConnectionFromPool). - Query Execution Errors: General failures during the execution of a query
(e.g.,
SingleStringRequestFailure,InsertDataFrameFailure). - Result Cardinality Errors: When a query returns an unexpected number of rows
(e.g.,
SingleIntegerRequestNoSingleResponse,MultipleStringRequestEmptyResponse). - Data Integrity and Validation Errors: Failures found during startup or runtime
validation checks (e.g.,
DatabaseBallingSetValTableContainsNull,DatabaseDataTableContainsTooManyRows). - Data Conversion Errors: When data retrieved from the database cannot be parsed
into the expected Rust type (e.g.,
TimestampConversionFailure).
Enums§
- SqlInterface
Error - Enum codifies the errors which the program may encounter in communication with the DB