Skip to main content

wayfinder_core/
error.rs

1//! The crate's error type.
2//!
3//! Public APIs return [`Result`]/[`enum@Error`] so downstream code can match on
4//! specific failure modes. Binaries (the `wf` CLI, the MCP server) still use
5//! `anyhow` and absorb these via `?`; only the library exposes typed errors.
6
7use thiserror::Error;
8
9/// An error from querying, caching, or parsing Archives of Nethys data.
10#[derive(Debug, Error)]
11pub enum Error {
12    /// The HTTP request to Archives of Nethys failed (network, TLS, timeout).
13    #[error("HTTP error talking to Archives of Nethys: {0}")]
14    Http(#[from] reqwest::Error),
15
16    /// Archives of Nethys returned a non-success HTTP status.
17    #[error("Archives of Nethys returned HTTP {status}")]
18    HttpStatus {
19        /// The HTTP status code returned.
20        status: u16,
21    },
22
23    /// A response could not be deserialized into the expected shape.
24    #[error("failed to parse Archives of Nethys response: {0}")]
25    Parse(#[from] serde_json::Error),
26
27    /// A response was valid JSON but missing an expected field.
28    #[error("unexpected Archives of Nethys response: {0}")]
29    UnexpectedResponse(String),
30
31    /// The local SQLite document cache failed.
32    #[error("cache error: {0}")]
33    Cache(#[from] rusqlite::Error),
34}
35
36/// Convenience alias for results from this crate.
37pub type Result<T, E = Error> = std::result::Result<T, E>;