tycho_execution/encoding/
errors.rs

1use std::{io, str::Utf8Error};
2
3use thiserror::Error;
4
5/// Represents the outer-level, user-facing errors of the tycho-execution encoding package.
6///
7/// `EncodingError` encompasses all possible errors that can occur in the package,
8/// wrapping lower-level errors in a user-friendly way for easier handling and display.
9/// Variants:
10/// - `InvalidInput`: Indicates that the encoding has failed due to bad input parameters.
11/// - `FatalError`: There is problem with the application setup.
12/// - `RecoverableError`: Indicates that the encoding has failed with a recoverable error. Retrying
13///   at a later time may succeed. It may have failed due to a temporary issue, such as a network
14///   problem.
15#[derive(Error, Debug, PartialEq)]
16pub enum EncodingError {
17    #[error("Invalid input: {0}")]
18    InvalidInput(String),
19    #[error("Fatal error: {0}")]
20    FatalError(String),
21    #[error("Recoverable error: {0}")]
22    RecoverableError(String),
23    #[error("Not implemented: {0}")]
24    NotImplementedError(String),
25}
26
27impl From<io::Error> for EncodingError {
28    fn from(err: io::Error) -> Self {
29        EncodingError::FatalError(err.to_string())
30    }
31}
32
33impl From<serde_json::Error> for EncodingError {
34    fn from(err: serde_json::Error) -> Self {
35        EncodingError::FatalError(err.to_string())
36    }
37}
38
39impl From<Utf8Error> for EncodingError {
40    fn from(err: Utf8Error) -> Self {
41        EncodingError::FatalError(err.to_string())
42    }
43}