|
|
@ -1,5 +1,6 @@
|
|
|
|
use std::{io, path::PathBuf};
|
|
|
|
use std::{io, path::PathBuf};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use miette::Diagnostic;
|
|
|
|
use thiserror::Error;
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
|
|
pub type AppResult<T> = std::result::Result<T, AppError>;
|
|
|
|
pub type AppResult<T> = std::result::Result<T, AppError>;
|
|
|
@ -31,18 +32,18 @@ pub enum AppError {
|
|
|
|
Chroot(#[from] ChrootError),
|
|
|
|
Chroot(#[from] ChrootError),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[derive(Error, Debug, Diagnostic)]
|
|
|
|
pub enum ScriptError {
|
|
|
|
pub enum ScriptError {
|
|
|
|
#[error("IO Error when trying to read script file: {0}")]
|
|
|
|
#[error("IO Error when trying to read script file: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::script::io_error))]
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Could not find the script file at {0}")]
|
|
|
|
#[error("Could not find the script file at {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::script::not_found))]
|
|
|
|
ScriptNotFound(PathBuf),
|
|
|
|
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}")]
|
|
|
|
#[error("Could not find the main method in the script file: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::script::no_main))]
|
|
|
|
MissingMain(PathBuf),
|
|
|
|
MissingMain(PathBuf),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -55,59 +56,75 @@ pub enum DistroConfigError {
|
|
|
|
InvalidToml(#[from] toml::de::Error),
|
|
|
|
InvalidToml(#[from] toml::de::Error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[derive(Error, Debug, Diagnostic)]
|
|
|
|
pub enum SchemaError {
|
|
|
|
pub enum SchemaError {
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::schema::io))]
|
|
|
|
#[error("IO Error when trying to read json-schema file: {0}")]
|
|
|
|
#[error("IO Error when trying to read json-schema file: {0}")]
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Encountered invalid JSON when parsing json-schema: {0}")]
|
|
|
|
#[error("Encountered invalid JSON when parsing json-schema: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::schema::invalid_json))]
|
|
|
|
InvalidJson(#[from] serde_json::Error),
|
|
|
|
InvalidJson(#[from] serde_json::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to parse the json-schema: {0}")]
|
|
|
|
#[error("Failed to parse the json-schema: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::schema::invalid_schema))]
|
|
|
|
ParseSchema(#[from] valico::json_schema::SchemaError),
|
|
|
|
ParseSchema(#[from] valico::json_schema::SchemaError),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[derive(Error, Debug, Diagnostic)]
|
|
|
|
pub enum OSConfigError {
|
|
|
|
pub enum OSConfigError {
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::os_config::io))]
|
|
|
|
#[error("IO Error when trying to read OSConfig file: {0}")]
|
|
|
|
#[error("IO Error when trying to read OSConfig file: {0}")]
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
Io(#[from] io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::os_config::invalid_json))]
|
|
|
|
#[error("Encountered invalid JSON when parsing OSConfig: {0}")]
|
|
|
|
#[error("Encountered invalid JSON when parsing OSConfig: {0}")]
|
|
|
|
InvalidJson(#[from] serde_json::Error),
|
|
|
|
InvalidJson(#[from] serde_json::Error),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::os_config::invalid))]
|
|
|
|
#[error("The os config is invalid:\n{0}")]
|
|
|
|
#[error("The os config is invalid:\n{0}")]
|
|
|
|
Validation(String),
|
|
|
|
Validation(String),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::os_config::missing_key))]
|
|
|
|
#[error("Missing config key {0}")]
|
|
|
|
#[error("Missing config key {0}")]
|
|
|
|
MissingConfigKey(String),
|
|
|
|
MissingConfigKey(String),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
#[derive(Error, Debug, Diagnostic)]
|
|
|
|
pub enum ChrootError {
|
|
|
|
pub enum ChrootError {
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::not_found))]
|
|
|
|
#[error("Could not find chroot directory {0}")]
|
|
|
|
#[error("Could not find chroot directory {0}")]
|
|
|
|
NotFound(PathBuf),
|
|
|
|
NotFound(PathBuf),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to unshare FS resources with parent: {0}")]
|
|
|
|
#[error("Failed to unshare FS resources with parent: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::unshare))]
|
|
|
|
Unshare(io::Error),
|
|
|
|
Unshare(io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to create chroot dir: {0}")]
|
|
|
|
#[error("Failed to create chroot dir: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::create))]
|
|
|
|
CreateChroot(io::Error),
|
|
|
|
CreateChroot(io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to chroot: {0}")]
|
|
|
|
#[error("Failed to chroot: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::enter))]
|
|
|
|
Chroot(io::Error),
|
|
|
|
Chroot(io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to mount directory {0} in chroot: {1}")]
|
|
|
|
#[error("Failed to mount directory {0} in chroot: {1}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::mount))]
|
|
|
|
Mount(PathBuf, io::Error),
|
|
|
|
Mount(PathBuf, io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to create symlink {0} in chroot: {1}")]
|
|
|
|
#[error("Failed to create symlink to {0} in chroot: {1}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::symlink))]
|
|
|
|
Link(PathBuf, io::Error),
|
|
|
|
Link(PathBuf, io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to remove symlink in chroot: {0}")]
|
|
|
|
#[error("Failed to remove symlink in chroot: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::unlink))]
|
|
|
|
Unlink(io::Error),
|
|
|
|
Unlink(io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to copy file {0} to chroot: {1}")]
|
|
|
|
#[error("Failed to copy file {0} to chroot: {1}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::copy_file))]
|
|
|
|
Copy(PathBuf, io::Error),
|
|
|
|
Copy(PathBuf, io::Error),
|
|
|
|
|
|
|
|
|
|
|
|
#[error("Failed to change process working directory: {0}")]
|
|
|
|
#[error("Failed to change process working directory: {0}")]
|
|
|
|
|
|
|
|
#[diagnostic(code(trm::chroot::chdir))]
|
|
|
|
ChDir(io::Error),
|
|
|
|
ChDir(io::Error),
|
|
|
|
}
|
|
|
|
}
|
|
|
|