Module balling_error

Source
Expand description

Contains error definitions for Balling Defines the custom error types for the Balling mineral dosing system.

This module contains the BallingError enum, which consolidates all potential failures that can occur during the initialization and execution of the Balling dosing controller. By using a dedicated, descriptive error type, the system can provide clear diagnostics when the dosing logic fails.

§Design and Purpose

The BallingError enum is designed using the thiserror crate to provide structured and informative error messages.

  • Source Chaining: For errors originating from the database layer (e.g., SetValueRetrievalError), the #[source] attribute preserves the underlying SqlInterfaceError. This creates a full error chain, which is invaluable for debugging the root cause of a database failure.

  • Rich Context: Each error variant is designed to include important context, such as the code location and the specific pump_id that was involved when the error occurred.

§Error Categories

The errors fall into two main categories:

  1. Configuration Validation Errors: These errors occur at startup when the Balling::new() constructor validates the configuration. They prevent the application from starting with an invalid or illogical setup.

    • ScheduleCheckIntervalZero
    • DosingIntervalShorterThanCheckInterval
    • InvalidDosingInterval
  2. Runtime Errors: These errors can occur while the Balling thread is running.

    • SetValueRetrievalError: A failure to fetch pump settings from the database.
    • ReadDurationSinceLastDosingFailure: A failure to calculate the time since the last dosing event.
    • CountdownCalculationInvalidPumpId: An internal logic error indicating an invalid pump ID was used.

Enums§

BallingError
Contains error definitions for Balling