Skip to main content

wickra_proof_core/
error.rs

1//! Error type for `wickra-proof-core`.
2
3/// Errors returned by wickra-proof-core operations. Every fallible boundary (parsing,
4/// engine invocation, canonicalization) maps into one of these; no operation
5/// panics on caller-supplied input.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// A JSON or TOML value failed to parse.
9    #[error("parse: {0}")]
10    Parse(String),
11    /// The embedded strategy JSON is not a valid `StrategySpec`.
12    #[error("bad spec: {0}")]
13    BadSpec(String),
14    /// The pinned `engine_version` differs from the linked backtest engine.
15    #[error("engine mismatch: expected {expected}, linked {linked}")]
16    EngineMismatch {
17        /// The version pinned in the `ProofSpec`.
18        expected: String,
19        /// The version of the linked `wickra-backtest` engine.
20        linked: String,
21    },
22    /// The backtest engine returned an error.
23    #[error("backtest: {0}")]
24    Backtest(String),
25    /// The data map lacked the candles required by the strategy.
26    #[error("data: {0}")]
27    Data(String),
28}
29
30/// Result alias for wickra-proof-core.
31pub type Result<T> = core::result::Result<T, Error>;
32
33impl From<serde_json::Error> for Error {
34    fn from(e: serde_json::Error) -> Self {
35        Error::Parse(e.to_string())
36    }
37}