Module sql_interface_error

Source
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_interface and 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 by module_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., a mysql::Error or chrono::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, or SingleStringRequestNoSingleResponse.

§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§

SqlInterfaceError
Enum codifies the errors which the program may encounter in communication with the DB