aptu_core/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Error types for the Aptu CLI.
4//!
5//! Uses `thiserror` for deriving `std::error::Error` implementations.
6//! Application code should use `anyhow::Result` for top-level error handling.
7
8use thiserror::Error;
9
10/// Errors that can occur during Aptu operations.
11#[derive(Error, Debug)]
12pub enum AptuError {
13    /// GitHub API error from octocrab.
14    #[error("GitHub API error: {0}")]
15    GitHub(#[from] octocrab::Error),
16
17    /// AI provider error (`OpenRouter`, Ollama, etc.).
18    #[error("AI provider error: {message}")]
19    AI {
20        message: String,
21        status: Option<u16>,
22    },
23
24    /// User is not authenticated - needs to run `aptu auth login`.
25    #[error("Authentication required - run `aptu auth login` first")]
26    NotAuthenticated,
27
28    /// Rate limit exceeded from an AI provider.
29    #[error("Rate limit exceeded on {provider}, retry after {retry_after}s")]
30    RateLimited { provider: String, retry_after: u64 },
31
32    /// Configuration file error.
33    #[error("Configuration error: {0}")]
34    Config(#[from] config::ConfigError),
35
36    /// Invalid JSON response from AI provider.
37    #[error("Invalid JSON response from AI")]
38    InvalidAIResponse(#[source] serde_json::Error),
39
40    /// Network/HTTP error from reqwest.
41    #[error("Network error: {0}")]
42    Network(#[from] reqwest::Error),
43
44    /// Keyring/credential storage error.
45    #[error("Keyring error: {0}")]
46    Keyring(#[from] keyring::Error),
47}