use chrono::{DateTime, Utc};
use crate::Spline;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Clone, PartialEq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("no input points to interpolate")]
NoPoints,
#[error("invalid time range: start {start} is after end {end}")]
InvalidTimeRange {
start: DateTime<Utc>,
end: DateTime<Utc>,
},
#[error("invalid polynomial degree {degree}: must be between 1 and {max}")]
InvalidDegree {
degree: usize,
max: usize,
},
#[error("{timestamps} timestamps but {values} values")]
LengthMismatch {
timestamps: usize,
values: usize,
},
#[error("invalid bounds factor {0}: must be finite and not negative")]
InvalidBoundsFactor(f64),
#[error("input value at {timestamp} is not representable as a finite f64")]
ValueOutOfRange {
timestamp: DateTime<Utc>,
},
#[error("interpolated value at {timestamp} is beyond f64's range")]
NonFiniteResult {
timestamp: DateTime<Utc>,
},
#[error("output grid of {points} points is too large")]
OutputTooLarge {
points: u128,
},
#[error("{spline} needs at least {required} distinct points, got {available}")]
InsufficientPoints {
spline: Spline,
required: usize,
available: usize,
},
#[error("GPU unavailable: {0}")]
GpuUnavailable(String),
#[error("GPU error: {0}")]
Gpu(String),
#[error("GPU already configured: {0}")]
GpuAlreadyConfigured(&'static str),
#[error("cannot parse {kind} from {input:?}")]
Parse {
kind: &'static str,
input: String,
},
#[cfg(feature = "tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "tokio")))]
#[error("interpolation task failed: {0}")]
Task(String),
}