git_commit_sage/
error.rs

1use thiserror::Error;
2use reqwest::StatusCode;
3
4#[derive(Error, Debug)]
5pub enum Error {
6    #[error("Git error: {0}")]
7    Git(#[from] git2::Error),
8
9    #[error("API error: {}", .0.status().map_or("Network connection error. Please check your internet connection.", |s| match s {
10        StatusCode::SERVICE_UNAVAILABLE => "Together.ai service is temporarily unavailable. Please try again in a few moments.",
11        StatusCode::UNAUTHORIZED => "Invalid API key. Please check your Together.ai API key.",
12        StatusCode::TOO_MANY_REQUESTS => "Rate limit exceeded. Please wait a moment before trying again.",
13        _ => "Unexpected API error occurred.",
14    }))]
15    Request(#[from] reqwest::Error),
16
17    #[error("Environment error: {0}")]
18    Env(#[from] std::env::VarError),
19
20    #[error("IO error: {0}")]
21    Io(#[from] std::io::Error),
22
23    #[error("Configuration error: {0}")]
24    Config(#[from] toml::de::Error),
25
26    #[error("No changes to commit. Make sure you have staged your changes with 'git add'")]
27    NoChanges,
28
29    #[error("API key not provided. Set TOGETHER_API_KEY environment variable or use --api-key")]
30    NoApiKey,
31
32    #[error("Failed to generate commit message: {0}")]
33    CommitMessageGeneration(String),
34}
35
36pub type Result<T> = std::result::Result<T, Error>;