hashx/
err.rs

1//! Error types for the `hashx` crate
2
3use std::sync::Arc;
4
5/// Errors that could occur while building a hash function
6#[derive(Clone, Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// A whole-program constraint in HashX failed, and this particular
10    /// seed should be considered unusable and skipped.
11    #[error("HashX program can't be constructed for this specific seed")]
12    ProgramConstraints,
13
14    /// [`crate::RuntimeOption::CompileOnly`] is in use and the compiler failed.
15    #[error("HashX compiler failed and no fallback was enabled: {0}")]
16    Compiler(#[from] CompilerError),
17}
18
19/// Details about a compiler error
20#[derive(Clone, Debug, thiserror::Error)]
21#[non_exhaustive]
22pub enum CompilerError {
23    /// The compiler was not available for this build configuration.
24    #[error("There is no HashX compiler implementation available in this configuration")]
25    NotAvailable,
26
27    /// Failed to set up the runtime environment, with a [`std::io::Error`].
28    #[error("Runtime error while preparing the hash program: {0}")]
29    Runtime(#[source] Arc<std::io::Error>),
30}
31
32impl From<std::io::Error> for CompilerError {
33    fn from(err: std::io::Error) -> Self {
34        Self::Runtime(Arc::new(err))
35    }
36}