wickra_backtest_core/error.rs
1//! Error types for the backtest engine.
2//!
3//! All fallible paths return [`BacktestError`]; bindings map it to a stable
4//! integer code so no panic ever crosses an FFI boundary.
5
6use thiserror::Error;
7
8/// An error raised while parsing a strategy spec or running a backtest.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum BacktestError {
12 /// The strategy spec could not be parsed or was structurally invalid.
13 #[error("invalid strategy spec: {0}")]
14 InvalidSpec(String),
15
16 /// An indicator referenced in the spec is unknown to the registry.
17 #[error("unknown indicator type: {0}")]
18 UnknownIndicator(String),
19
20 /// An indicator was constructed with the wrong number or value of parameters.
21 #[error("invalid parameters for indicator {indicator}: {reason}")]
22 InvalidParams {
23 /// The indicator type name.
24 indicator: String,
25 /// Why the parameters were rejected.
26 reason: String,
27 },
28
29 /// A rule referenced an indicator name that is not declared in `indicators`.
30 #[error("rule references undeclared indicator: {0}")]
31 UndeclaredRef(String),
32
33 /// The input data was empty or malformed.
34 #[error("invalid input data: {0}")]
35 InvalidData(String),
36}
37
38/// Convenience result alias for the engine.
39pub type Result<T> = core::result::Result<T, BacktestError>;