1use std::fmt::Display;
2
3use anyhow::{anyhow, Context, Result};
4use thiserror::Error;
5
6use crate::io::RateLimitHeader;
7
8#[derive(Error, Debug)]
9pub enum GRError {
10 #[error("Precondition not met error: {0}")]
11 PreconditionNotMet(String),
12 #[error("Remote url not found. Make sure you are in a git repository: {0}")]
13 GitRemoteUrlNotFound(String),
14 #[error("--domain expected: {0}")]
15 DomainExpected(String),
16 #[error("--repo expected: {0}")]
17 RepoExpected(String),
18 #[error("Time conversion error: {0}")]
19 TimeConversionError(String),
20 #[error("Configuration error: {0}")]
21 ConfigurationError(String),
22 #[error("Operation not supported for this resource: {0}")]
23 OperationNotSupported(String),
24 #[error("RateLimit exceeded")]
25 RateLimitExceeded(RateLimitHeader),
26 #[error("Exponential backoff max retries reached: {0}")]
27 ExponentialBackoffMaxRetriesReached(String),
28 #[error("Application error: {0}")]
29 ApplicationError(String),
30 #[error(
33 "Remote unexpected response contract: Open issue at https://github.com/jordilin/gitar: {0}"
34 )]
35 RemoteUnexpectedResponseContract(String),
36 #[error("Remote server status error: {0}")]
37 RemoteServerError(String),
38 #[error("HTTP Transport error/network outage: {0}")]
39 HttpTransportError(String),
40 #[error("Mermaid parsing error: {0}")]
41 MermaidParsingError(String),
42 #[error("Configuration not found")]
43 ConfigurationNotFound,
44 #[error("Cache location does not exist: {0}")]
45 CacheLocationDoesNotExist(String),
46 #[error("Cache location is not a directory: {0}")]
47 CacheLocationIsNotADirectory(String),
48 #[error("Cache location is not writeable: {0}")]
49 CacheLocationIsNotWriteable(String),
50 #[error("Cache location write test failed: {0}")]
51 CacheLocationWriteTestFailed(String),
52 #[error("User not found: {0}")]
53 UserNotFound(String),
54}
55
56pub trait AddContext<T, E>: Context<T, E> {
57 fn err_context<C: Display + Send + Sync + 'static>(self, msg: C) -> Result<T, anyhow::Error>
58 where
59 Self: Sized,
60 {
61 self.with_context(|| msg.to_string())
62 }
63}
64
65impl<U, T, E> AddContext<T, E> for U where U: Context<T, E> {}
66
67pub fn gen<T: AsRef<str>>(msg: T) -> anyhow::Error {
68 anyhow!(msg.as_ref().to_string())
69}