noctua/src/error.rs
mow 1a0b8c49aa refactor: merge workspace (core/ + ui/) into a single flat binary crate
integrate CLI into main.rs, no lib.rs by design (YAGNI)
2026-03-10 19:20:57 +01:00

46 lines
1.2 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
// src/error.rs
//
// Central error and result types for Noctua.
use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[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<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Io(err)
}
}