Skip to main content

wickra_core/
error.rs

1//! Error types used across `wickra-core`.
2
3use thiserror::Error;
4
5/// Errors that can occur when constructing or operating on an indicator.
6#[derive(Debug, Clone, PartialEq, Eq, Error)]
7pub enum Error {
8    /// A period (window length) must be at least one.
9    #[error("period must be greater than zero")]
10    PeriodZero,
11
12    /// A specific minimum period requirement was not met (e.g. MACD needs slow > fast).
13    #[error("invalid period: {message}")]
14    InvalidPeriod { message: &'static str },
15
16    /// A non-finite value (NaN or infinity) was passed where a finite price was expected.
17    #[error("input value must be finite (got NaN or infinity)")]
18    NonFiniteInput,
19
20    /// A candle whose components do not form a valid bar (e.g. high < low) was provided.
21    #[error("invalid candle: {message}")]
22    InvalidCandle { message: &'static str },
23
24    /// A tick whose components do not satisfy the tick invariants (e.g. negative
25    /// volume) was provided. Ticks are a different concept from candles and
26    /// surface as their own variant so consumers of a tick-stream pipeline
27    /// can match on a semantically-correct error instead of `InvalidCandle`.
28    #[error("invalid tick: {message}")]
29    InvalidTick { message: &'static str },
30
31    /// A multiplier or factor must be strictly positive.
32    #[error("multiplier must be greater than zero")]
33    NonPositiveMultiplier,
34}
35
36/// Convenience alias for `Result<T, wickra_core::Error>`.
37pub type Result<T> = core::result::Result<T, Error>;