Skip to main content

confium_test_harness/
error.rs

1//! Errors for the test harness.
2//!
3//! Snafu-based, mirroring the pattern used across the workspace. Vector
4//! parsing, runner, and reporting all funnel through [`Error`].
5
6use snafu::Backtrace;
7use snafu::Snafu;
8
9pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(Snafu, Debug)]
12#[snafu(visibility(pub))]
13pub enum Error {
14    #[snafu(display("Malformed test vector: {}", message))]
15    Vector {
16        message: String,
17        backtrace: Backtrace,
18    },
19
20    #[snafu(display("Underlying threshold-cryptography error: {}", source))]
21    Tc {
22        #[snafu(backtrace)]
23        source: confium_tc::Error,
24    },
25
26    #[snafu(display("Session did not complete after {} rounds", rounds))]
27    SessionDidNotComplete { rounds: u8, backtrace: Backtrace },
28
29    #[snafu(display("JSON serialization error: {}", source))]
30    Json {
31        source: serde_json::Error,
32        backtrace: Backtrace,
33    },
34}
35
36impl From<confium_tc::Error> for Error {
37    fn from(source: confium_tc::Error) -> Self {
38        Error::Tc { source }
39    }
40}
41
42impl From<serde_json::Error> for Error {
43    fn from(source: serde_json::Error) -> Self {
44        Error::Json {
45            source,
46            backtrace: Backtrace::capture(),
47        }
48    }
49}