use std::{io, path::PathBuf}; use thiserror::Error; pub type AppResult = std::result::Result; #[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), #[error(transparent)] Chroot(#[from] ChrootError), } #[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), } #[derive(Error, Debug)] pub enum ChrootError { #[error("Could not find chroot directory {0}")] NotFound(PathBuf), #[error("Failed to unshare FS resources with parent: {0}")] Unshare(io::Error), #[error("Failed to create chroot dir: {0}")] CreateChroot(io::Error), #[error("Failed to chroot: {0}")] Chroot(io::Error), #[error("Failed to mount directory {0} in chroot: {1}")] Mount(PathBuf, io::Error), #[error("Failed to create symlink {0} in chroot: {1}")] Link(PathBuf, io::Error), #[error("Failed to remove symlink in chroot: {0}")] Unlink(io::Error), #[error("Failed to change process working directory: {0}")] ChDir(io::Error), }