prompt_store/api/
error.rs

1//! Error types for the library API.
2
3use llm::error::LLMError;
4use thiserror::Error;
5
6/// Errors related to the prompt store (file access, crypto, etc.).
7#[derive(Error, Debug)]
8pub enum StoreError {
9    /// An error occurred during store initialization.
10    #[error("Failed to initialize store: {0}")]
11    Init(String),
12
13    /// The requested prompt or chain could not be found by its ID or title.
14    #[error("Prompt or chain '{0}' not found")]
15    NotFound(String),
16
17    /// A given ID exists for both a prompt and a chain, causing ambiguity.
18    #[error("ID '{0}' is ambiguous (found both a prompt and a chain)")]
19    AmbiguousId(String),
20
21    /// A given title matches multiple prompts or chains.
22    #[error("Title '{0}' is ambiguous (multiple matches found)")]
23    AmbiguousTitle(String),
24
25    /// The API was used with an invalid configuration.
26    #[error("Configuration error: {0}")]
27    Configuration(String),
28
29    /// An underlying file I/O error occurred.
30    #[error("I/O error: {0}")]
31    Io(#[from] std::io::Error),
32
33    /// A cryptographic operation (encryption/decryption) failed.
34    #[error("Crypto error: {0}")]
35    Crypto(String),
36
37    /// Failed to serialize or deserialize data.
38    #[error("JSON parsing error: {0}")]
39    Json(#[from] serde_json::Error),
40}
41
42/// A comprehensive error type for all operations in the library API.
43#[derive(Error, Debug)]
44pub enum RunError {
45    /// An error originating from the prompt store itself.
46    #[error(transparent)]
47    Store(#[from] StoreError),
48
49    /// An error originating from the underlying LLM backend.
50    #[error("LLM backend error: {0}")]
51    LLM(#[from] LLMError),
52}