autocrate/src/error.rs

65 lines
2.1 KiB
Rust
Raw Normal View History

2024-02-24 13:24:14 +01:00
use std::{env::VarError, path::PathBuf, process::ExitStatus, string::FromUtf8Error};
2024-01-27 23:26:49 +01:00
use anyhow;
use thiserror::Error;
2024-01-25 22:33:48 +01:00
use crate::config::ApiAuth;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
/// Bad IO operation
#[error("Bad IO operation")]
IO(#[from] std::io::Error),
2024-01-25 22:33:48 +01:00
#[error("Bad configuration file")]
Config(#[from] ConfigError),
#[error(transparent)]
Other(#[from] anyhow::Error),
#[error("Yaml error")]
2024-01-25 22:33:48 +01:00
SerdeYaml(#[from] serde_yaml::Error),
2024-01-28 01:19:46 +01:00
#[error("Could not generate the changelog")]
ChangelogError(#[from] ChangelogError),
2024-02-24 14:10:44 +01:00
#[error("Server Api error")]
2024-02-24 14:44:06 +01:00
ServerApiError(#[from] ServerApiError),
2024-02-24 14:10:44 +01:00
}
#[derive(Error, Debug)]
pub enum ServerApiError {
#[error(transparent)]
ParseUrl(#[from] url::ParseError),
#[error(transparent)]
InvalidHeaderValue(#[from] reqwest::header::InvalidHeaderValue),
#[error(transparent)]
2024-02-24 14:44:06 +01:00
ReqwestErr(#[from] reqwest::Error),
2024-01-25 22:33:48 +01:00
}
2024-01-28 01:19:46 +01:00
#[derive(Error, Debug)]
pub enum ChangelogError {
#[error("changelog has 'enabled = false' in the yaml config")]
IsDisabledButUsed,
#[error("error while using `git log`, is git installed?")]
GitCommandError,
#[error("error while using `git log`, could not format stdout with utf8")]
GitUTF8Error(#[from] FromUtf8Error),
2024-01-28 01:33:43 +01:00
#[error("git exited with status {0}: {1}")]
GitBadStatus(ExitStatus, String),
2024-01-28 01:19:46 +01:00
}
2024-01-25 22:33:48 +01:00
#[derive(Error, Debug)]
pub enum ConfigError {
#[error("could not find git repository")]
GitRepoNotFound,
#[error("no \".autocrate.yaml\" or \".autocrate.yml\" found in repository root")]
NoYamlFile,
#[error("the autocrate config file is not a regular file (is it a directory?)")]
YamlFileIsNotFile,
#[error("api {0:?} provides both a `pass` and a `pass_file`")]
YamlApiAuthBothPass(ApiAuth),
2024-01-27 23:26:49 +01:00
#[error("password provided as file, but does not exist: {0}")]
PassFileDoesNotExist(PathBuf),
2024-02-24 13:24:14 +01:00
#[error("config requires environment variable {0}, but {0} is not set")]
EnvNotSet(String),
#[error("Bad value for environment variable: {0}")]
BadEnv(#[from] VarError),
}