zetasketch_rs/error.rs
1// SPDX-FileCopyrightText: 2025 Daniel Vrátil <me@dvratil.cz>
2//
3// SPDX-License-Identifier: MIT
4//
5// Based on the original Zetasketch implementation by Google:
6// https://github.com/google/zetasketch
7// Published under the Apache License 2.0
8
9use thiserror::Error;
10
11/// Error type for the ZetaSketch library.
12#[derive(Error, Debug)]
13pub enum SketchError {
14 /// An operation was attempted on an aggregator with a different type than the one expected.
15 #[error("Incompatible precision: {0}")]
16 IncompatiblePrecision(String),
17 /// An operation was attempted on an aggregator with an invalid state.
18 #[error("Invalid HLL++ state: {0}")]
19 InvalidState(String),
20 /// An error occurred while serializing the aggregator state to a protocol buffer.
21 #[error("Proto serialization error: {0}")]
22 ProtoSerialization(protobuf::Error),
23 /// An error occurred while deserializing the aggregator state from a protocol buffer.
24 #[error("Proto deserialization error: {0}")]
25 ProtoDeserialization(protobuf::Error),
26 /// An error occurred while reading or writing to a file.
27 #[error("IO error: {0}")]
28 Io(#[from] std::io::Error),
29 /// An operation was attempted with an invalid argument.
30 #[error("Invalid argument: {0}")]
31 IllegalArgument(String),
32 /// An error occurred while performing a generic operation.
33 #[error("Generic error: {0}")]
34 Generic(String),
35}