You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tourmaline/src/error.rs

81 lines
2.0 KiB
Rust

use std::{io, path::PathBuf};
use thiserror::Error;
pub type AppResult<T> = std::result::Result<T, AppError>;
#[derive(Error, Debug)]
pub enum AppError {
#[error("Missing config")]
MissingConfig,
#[error("IO Error: {0}")]
Io(#[from] io::Error),
#[error("JSON deserialization error {0}")]
JSON(#[from] serde_json::Error),
#[error(transparent)]
Script(#[from] ScriptError),
#[error(transparent)]
DistroConfig(#[from] DistroConfigError),
#[error(transparent)]
Schema(#[from] SchemaError),
#[error(transparent)]
OSConfig(#[from] OSConfigError),
}
#[derive(Error, Debug)]
pub enum ScriptError {
#[error("IO Error when trying to read script file: {0}")]
Io(#[from] io::Error),
#[error("Could not find the script file at {0}")]
ScriptNotFound(PathBuf),
#[error("Nu error when executing script: {0}")]
NuError(#[from] embed_nu::Error),
#[error("Could not find the main method in the script file: {0}")]
MissingMain(PathBuf),
}
#[derive(Error, Debug)]
pub enum DistroConfigError {
#[error("IO Error when trying to read distro config: {0}")]
Io(#[from] io::Error),
#[error("Encountered invalid Toml when parsing distro config: {0}")]
InvalidToml(#[from] toml::de::Error),
}
#[derive(Error, Debug)]
pub enum SchemaError {
#[error("IO Error when trying to read json-schema file: {0}")]
Io(#[from] io::Error),
#[error("Encountered invalid JSON when parsing json-schema: {0}")]
InvalidJson(#[from] serde_json::Error),
#[error("Failed to parse the json-schema: {0}")]
ParseSchema(#[from] valico::json_schema::SchemaError),
}
#[derive(Error, Debug)]
pub enum OSConfigError {
#[error("IO Error when trying to read OSConfig file: {0}")]
Io(#[from] io::Error),
#[error("Encountered invalid JSON when parsing OSConfig: {0}")]
InvalidJson(#[from] serde_json::Error),
#[error("The os config is invalid:\n{0}")]
Validation(String),
#[error("Missing config key {0}")]
MissingConfigKey(String),
}