use std::path::PathBuf;
use masterror::{AppCode, AppErrorKind, Error};
#[derive(Debug, Error)]
#[error("failed to read file '{path}': {source}")]
#[app_error(kind = AppErrorKind::Internal, code = AppCode::Internal, message)]
pub struct FileReadError {
pub path: String,
pub source: std::io::Error,
}
impl FileReadError {
pub fn new(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Self {
path: path.into().display().to_string(),
source,
}
}
}
#[derive(Debug, Error)]
#[error("failed to parse '{path}': {message}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
pub struct ParseError {
pub path: String,
pub message: String,
}
impl ParseError {
pub fn new(path: impl Into<PathBuf>, message: impl Into<String>) -> Self {
Self {
path: path.into().display().to_string(),
message: message.into(),
}
}
}
#[derive(Debug, Error)]
#[error("failed to parse diff: {message}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
pub struct DiffParseError {
pub message: String,
}
#[derive(Debug, Error)]
#[error("failed to parse config '{path}': {message}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
pub struct ConfigError {
pub path: String,
pub message: String,
}
impl ConfigError {
pub fn new(path: impl Into<PathBuf>, message: impl Into<String>) -> Self {
Self {
path: path.into().display().to_string(),
message: message.into(),
}
}
}
#[derive(Debug, Error)]
#[error("invalid config field '{field}': {message}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
pub struct ConfigValidationError {
pub field: String,
pub message: String,
}
#[derive(Debug, Error)]
#[error("output error for format '{format}': {message}")]
#[app_error(kind = AppErrorKind::Internal, code = AppCode::Internal, message)]
pub struct OutputError {
pub format: String,
pub message: String,
}
#[derive(Debug, Error)]
#[error("limit exceeded for '{limit_type}': {actual} > {maximum}")]
#[app_error(kind = AppErrorKind::BadRequest, code = AppCode::BadRequest, message)]
pub struct LimitExceededError {
pub limit_type: String,
pub actual: usize,
pub maximum: usize,
}
#[derive(Debug, Error)]
#[error("io error: {0}")]
#[app_error(kind = AppErrorKind::Internal, code = AppCode::Internal, message)]
pub struct IoError(pub std::io::Error);