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/// A type alias for `Result<T, doing::Error>`.
22pub type Result<T> = std::result::Result<T, Error>;
23
24/// Errors that can occur within the doing crate.
25#[derive(Debug, thiserror::Error)]
26pub enum Error {
27 /// An error occurred while reading or writing configuration.
28 #[error("configuration error: {0}")]
29 Config(String),
30
31 /// The requested undo/redo operation exceeds available history.
32 #[error("{0}")]
33 HistoryLimit(String),
34
35 /// An invalid or unrecognized time expression was provided.
36 #[error("invalid time expression: {0}")]
37 InvalidTimeExpression(String),
38
39 /// An I/O error occurred.
40 #[error(transparent)]
41 Io(#[from] io::Error),
42
43 /// An error occurred while parsing input.
44 #[error("parse error: {0}")]
45 Parse(String),
46
47 /// An error occurred in the plugin system.
48 #[error("plugin error: {0}")]
49 Plugin(String),
50
51 /// An error occurred during self-update.
52 #[error("update error: {0}")]
53 Update(String),
54}
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}