git_auth/
error.rs

1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum GitError {
6    #[error("Error loading stdin: {0}")]
7    Io(#[from] io::Error),
8
9    #[error("Required info missing from input: {0:?}")]
10    MissingInfo(String),
11}
12
13#[derive(Error, Debug)]
14pub enum DatabaseError {
15    #[error("Error constructing database paths")]
16    Path,
17
18    #[error("Error managing database file: {0}")]
19    Io(#[from] io::Error),
20
21    #[error("Rusqlite error: {0}")]
22    Sqlite(#[from] rusqlite::Error),
23}
24
25#[derive(Error, Debug)]
26pub enum GithubError {
27    #[error("{0}")]
28    ReqwestError(#[from] reqwest::Error),
29
30    #[error("Missing field {0} in api response")]
31    MissingField(String),
32
33    #[error("API response field {0} contained invalid or unexpected data")]
34    InvalidField(String),
35
36    #[error("Timed out waiting for authentication. Token only valif for {0}s")]
37    Timeout(i32),
38
39    #[error("Keyring failed to store token: {0}")]
40    KeyingError(#[from] keyring::Error),
41}
42
43#[derive(Error, Debug)]
44pub enum Error {
45    #[error("{0}")]
46    GithubError(#[from] GithubError),
47
48    #[error("{0}")]
49    GitError(#[from] GitError),
50
51    #[error("{0}")]
52    DatabaseError(#[from] DatabaseError),
53
54    #[error("{0}")]
55    PromptError(#[from] inquire::error::InquireError),
56}
57
58// #[cfg(test)]
59// mod tests {
60//     use super::*;
61//     use std::fs;
62//
63//     #[test]
64//     fn test_error() {
65//         let io_error = fs::read_to_string("fake/path.txt");
66//         assert!(io_error.is_err());
67//         if let Err(err) = io_error {
68//             assert_eq!(format!("{}", err), format!("{}", GitRequestError::Io(err)))
69//         }
70//     }
71// }