use std::backtrace::Backtrace;
use thiserror::Error;
pub type ProxmoxResult<T> = Result<T, ProxmoxError>;
#[derive(Debug, Error)]
pub enum ProxmoxError {
#[error("Authentication error: {0}")]
Authentication(String),
#[error("Connection error: {0}")]
Connection(String),
#[error("Validation error")]
Validation {
source: ValidationError,
backtrace: Backtrace,
},
#[error("Session error: {0}")]
Session(String),
#[error("Unexpected error: {0}")]
Unexpected(String),
}
#[derive(Debug, Error)]
pub enum ValidationError {
#[error("Field '{field}' is invalid: {message}")]
Field { field: String, message: String },
#[error("Format error: {0}")]
Format(String),
#[error("Constraint violation: {0}")]
ConstraintViolation(String),
}
impl From<std::io::Error> for ProxmoxError {
fn from(err: std::io::Error) -> Self {
ProxmoxError::Session(err.to_string())
}
}
impl From<serde_json::Error> for ProxmoxError {
fn from(err: serde_json::Error) -> Self {
ProxmoxError::Session(err.to_string())
}
}