apache_datasketches/error.rs
1//! The single error type shared across every sketch family in this crate.
2
3use thiserror::Error;
4
5/// Error type shared across all sketch families (HLL, Theta, CPC) in this
6/// crate — there is no per-family error type.
7#[derive(Debug, Error)]
8pub enum SketchError {
9 /// A builder or constructor was given an out-of-range configuration
10 /// value (e.g. `lg_k`/`lg_config_k` outside its valid bounds, or a
11 /// `num_std_dev` outside `1..=3`). The underlying C++ layer rejected the
12 /// value; the string is its exception message.
13 #[error("invalid sketch configuration: {0}")]
14 InvalidConfig(String),
15
16 /// `deserialize`/`deserialize_compressed`/`wrap` was given bytes that
17 /// don't parse as a valid serialized sketch (e.g. truncated, corrupt,
18 /// or produced by an incompatible seed).
19 #[error("failed to deserialize sketch: {0}")]
20 Deserialization(String),
21
22 /// A catch-all for any other C++ exception that crossed the FFI
23 /// boundary, carrying its `what()` message. Prefer matching on a more
24 /// specific variant above when one applies.
25 #[error("datasketches C++ error: {0}")]
26 Cpp(String),
27
28 /// `ThetaIntersection::get_result()` was called before any `update()`.
29 #[error("intersection has no result: no update() call has been made yet")]
30 EmptyIntersection,
31}
32
33impl From<cxx::Exception> for SketchError {
34 fn from(e: cxx::Exception) -> Self {
35 SketchError::Cpp(e.what().to_string())
36 }
37}