// SPDX-License-Identifier: GPL-3.0-or-later // src/error.rs // // Central error and result types for Noctua. use std::fmt; pub type Result = std::result::Result; #[derive(Debug)] pub enum Error { /// A requested file or resource was not found. NotFound(String), /// The file format or operation is not supported. Unsupported(String), /// A session could not be loaded or saved. Session(String), /// An underlying I/O error. Io(std::io::Error), } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::NotFound(msg) => write!(f, "Not found: {msg}"), Error::Unsupported(msg) => write!(f, "Unsupported: {msg}"), Error::Session(msg) => write!(f, "Session error: {msg}"), Error::Io(err) => write!(f, "I/O error: {err}"), } } } impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Error::Io(err) => Some(err), _ => None, } } } impl From for Error { fn from(err: std::io::Error) -> Self { Error::Io(err) } }