diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-26 10:00:45 +0100 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-12-26 10:01:56 +0100 |
commit | a3111a5d214db66b7d676940b8f8bfda5074bd45 (patch) | |
tree | a68cc1458386052a7c97a07b69bd161866ad7046 /pkgs/by-name/ba/back/src/error/mod.rs | |
parent | fix(hosts/server2): Use correct path to `vhack.eu/nixos-server` repo (diff) | |
download | nixos-server-a3111a5d214db66b7d676940b8f8bfda5074bd45.tar.gz nixos-server-a3111a5d214db66b7d676940b8f8bfda5074bd45.zip |
fix(pkgs/back): Use rocket to manage the configuration values
This reduces the amount of needed `unwraps`/`expects` and allows us to streamline the parsing processes.
Diffstat (limited to 'pkgs/by-name/ba/back/src/error/mod.rs')
-rw-r--r-- | pkgs/by-name/ba/back/src/error/mod.rs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pkgs/by-name/ba/back/src/error/mod.rs b/pkgs/by-name/ba/back/src/error/mod.rs new file mode 100644 index 0000000..7e1c9cf --- /dev/null +++ b/pkgs/by-name/ba/back/src/error/mod.rs @@ -0,0 +1,56 @@ +use std::{fmt::Display, io, path::PathBuf}; + +use thiserror::Error; + +pub type Result<T> = std::result::Result<T, Error>; + +#[derive(Error, Debug)] +pub enum Error { + ConfigParse { + file: PathBuf, + error: serde_json::Error, + }, + ConfigRead { + file: PathBuf, + error: io::Error, + }, + RepoOpen { + repository_path: PathBuf, + error: Box<gix::open::Error>, + }, + RocketLaunch(#[from] rocket::Error), +} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::ConfigParse { file, error } => { + write!( + f, + "while trying to parse the config file ({}): {error}", + file.display() + ) + } + Error::ConfigRead { file, error } => { + write!( + f, + "while trying to read the config file ({}): {error}", + file.display() + ) + } + Error::RepoOpen { + repository_path, + error, + } => { + write!( + f, + "while trying to open the repository ({}): {error}", + repository_path.display() + ) + } + Error::RocketLaunch(error) => { + write!(f, "while trying to start back: {error}") + } + } + } +} |