34 lines
978 B
Rust
34 lines
978 B
Rust
//! The error type shared by the core modules.
|
|
|
|
use std::io;
|
|
|
|
/// Everything a core operation can fail with. The `Display` text is shown to the
|
|
/// user as-is, so validation messages are written in Czech like the rest of the UI.
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum CoreError {
|
|
/// Invalid input (bad year, empty title, unknown 3D format, …).
|
|
#[error("{0}")]
|
|
Invalid(String),
|
|
/// The target already exists and the caller asked not to overwrite it.
|
|
#[error("{0}")]
|
|
Exists(String),
|
|
/// Something expected on disk is missing.
|
|
#[error("{0}")]
|
|
NotFound(String),
|
|
/// A remote service (TMDb, ČSFD, Jellyfin) failed.
|
|
#[error("{0}")]
|
|
Remote(String),
|
|
#[error(transparent)]
|
|
Io(#[from] io::Error),
|
|
#[error(transparent)]
|
|
Json(#[from] serde_json::Error),
|
|
}
|
|
|
|
impl CoreError {
|
|
pub fn invalid(msg: impl Into<String>) -> Self {
|
|
Self::Invalid(msg.into())
|
|
}
|
|
}
|
|
|
|
pub type CoreResult<T> = Result<T, CoreError>;
|