Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
49 lines (46 loc) · 1.89 KB
/
Copy patherror.rs
File metadata and controls
49 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! A typed error for formwatch's library surface.
//!
//! The original code used `anyhow::Error` throughout, which is a fine
//! choice for a binary but unhelpful for embedders: a downstream caller
//! can't match on *why* something failed, only print it. This module adds
//! a `thiserror`-derived [`Error`] so new (and progressively, existing)
//! fallible APIs can return structured errors, while
//! [`Error::Other`] wraps an `anyhow::Error` so the two interop freely
//! and nothing had to be rewritten in one risky sweep.
use thiserror::Error;
/// The library's structured error type.
#[derive(Debug, Error)]
pub enum Error {
/// A configuration file or environment variable was invalid.
#[error("configuration error: {0}")]
Config(String),
/// An action was refused because the operator hadn't acknowledged the
/// authorized-use notice.
#[error("authorization error: {0}")]
Unauthorized(String),
/// A regression notification couldn't be delivered.
#[error("notification error: {0}")]
Notify(String),
/// An LLM-backed semantic check failed (configuration, transport, or an
/// unparseable reply).
#[error("LLM error: {0}")]
Llm(String),
/// An I/O operation failed.
#[error(transparent)]
Io(#[from] std::io::Error),
/// JSON (de)serialization failed.
#[error(transparent)]
Json(#[from] serde_json::Error),
/// YAML (de)serialization failed.
#[error(transparent)]
Yaml(#[from] serde_yaml::Error),
/// An HTTP request (e.g. a webhook delivery) failed.
#[error(transparent)]
Http(#[from] reqwest::Error),
/// Any other error, carried through from the existing `anyhow`-based
/// code so the two error styles compose without a rewrite.
#[error(transparent)]
Other(#[from] anyhow::Error),
}
/// Convenience alias for `Result<T, formwatch::error::Error>`.
pub type Result<T> = std::result::Result<T, Error>;