tetanes_core/
error.rs

1//! Error handling.
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
9#[must_use]
10pub enum Error {
11    #[error("invalid save version (expected {expected:?}, found: {found:?})")]
12    InvalidSaveVersion {
13        expected: &'static str,
14        found: String,
15    },
16    #[error("invalid tetanes header (path: {path:?}. {error}")]
17    InvalidSaveHeader { path: PathBuf, error: String },
18    #[error("invalid configuration {value:?} for {field:?}")]
19    InvalidConfig { field: &'static str, value: String },
20    #[error("{context}: {source:?}")]
21    Io {
22        context: String,
23        source: std::io::Error,
24    },
25    #[error("{0}")]
26    Unknown(String),
27}
28
29impl Error {
30    pub fn io(source: std::io::Error, context: impl Into<String>) -> Self {
31        Self::Io {
32            context: context.into(),
33            source,
34        }
35    }
36}