doing_error/lib.rs
1//! Shared error types for the doing workspace.
2//!
3//! This crate defines the [`Error`] enum and [`Result`] type alias used across all
4//! `doing-*` crates. It sits at the bottom of the dependency graph so every crate
5//! can return a uniform error type without pulling in heavy dependencies.
6//!
7//! # Error variants
8//!
9//! | Variant | Produced by |
10//! |----------------------------|--------------------------------------------------|
11//! | [`Error::Config`] | Configuration parsing and validation |
12//! | [`Error::HistoryLimit`] | Undo/redo when no further history is available |
13//! | [`Error::InvalidTimeExpression`] | Natural-language time parsing failures |
14//! | [`Error::Io`] | Filesystem and I/O operations (via `From<io::Error>`) |
15//! | [`Error::Parse`] | General input parsing (tags, queries, documents) |
16//! | [`Error::Plugin`] | Export/import plugin failures |
17//! | [`Error::Update`] | Self-update mechanism failures |
18
19use std::io;
20
21/// Errors that can occur within the doing crate.
22#[derive(Debug, thiserror::Error)]
23pub enum Error {
24 /// An error occurred while reading or writing configuration.
25 #[error("configuration error: {0}")]
26 Config(String),
27
28 /// The requested undo/redo operation exceeds available history.
29 #[error("{0}")]
30 HistoryLimit(String),
31
32 /// An invalid or unrecognized time expression was provided.
33 #[error("invalid time expression: {0}")]
34 InvalidTimeExpression(String),
35
36 /// An I/O error occurred.
37 #[error(transparent)]
38 Io(#[from] io::Error),
39
40 /// An error occurred while parsing input.
41 #[error("parse error: {0}")]
42 Parse(String),
43
44 /// An error occurred in the plugin system.
45 #[error("plugin error: {0}")]
46 Plugin(String),
47
48 /// An error occurred during self-update.
49 #[error("update error: {0}")]
50 Update(String),
51}
52
53/// A type alias for `Result<T, doing::Error>`.
54pub type Result<T> = std::result::Result<T, Error>;
55
56#[cfg(test)]
57mod test {
58 use super::*;
59
60 mod from {
61 use super::*;
62
63 #[test]
64 fn it_converts_from_io_error() {
65 let io_err = io::Error::new(io::ErrorKind::PermissionDenied, "access denied");
66 let error: Error = io_err.into();
67
68 assert!(matches!(error, Error::Io(_)));
69 }
70 }
71}