add start of error handling
This commit is contained in:
parent
4cbd6fcf2b
commit
66424f704d
6 changed files with 1457 additions and 15 deletions
18
src/data.rs
18
src/data.rs
|
@ -1,5 +1,6 @@
|
|||
//! Data structs. used by gregory and stuff for handling them
|
||||
|
||||
use crate::errors::Error;
|
||||
use serde::Deserialize;
|
||||
use std::time;
|
||||
use std::{collections::HashMap, fs, thread};
|
||||
|
@ -83,7 +84,7 @@ pub(crate) struct Package {
|
|||
pub(crate) struct JobExitStatus {
|
||||
pub(crate) job: Job,
|
||||
/// The [`Job`] this status is from
|
||||
///
|
||||
///
|
||||
/// This is stored as a u16 rather than a u8 so that 65535 can be returned if there is no exit code rather than doing an Option or something, which I fear will probably come back to haunt me, but whatever
|
||||
pub(crate) exit_code: u16,
|
||||
/// Where the log is
|
||||
|
@ -97,9 +98,18 @@ pub(crate) struct JobExitStatus {
|
|||
pub(crate) container_name: String,
|
||||
}
|
||||
|
||||
pub(crate) fn config_from_file(filename: String) -> Config {
|
||||
let toml: Config = toml::from_str(fs::read_to_string(filename).unwrap().as_str()).unwrap();
|
||||
return toml;
|
||||
pub(crate) fn config_from_file(filename: String) -> Result<Config, Error> {
|
||||
match fs::read_to_string(filename) {
|
||||
Ok(raw_data) => match toml::from_str(raw_data.as_str()) {
|
||||
Ok(conf) => return Ok(conf),
|
||||
Err(e) => {
|
||||
return Err(Error::DeserError(e));
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
return Err(Error::IOError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================
|
||||
|
|
13
src/errors.rs
Normal file
13
src/errors.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("io error: {0}")]
|
||||
IOError(#[from] std::io::Error),
|
||||
|
||||
#[error("error while deserializing TOML: {0}")]
|
||||
DeserError(#[from] toml::de::Error),
|
||||
|
||||
#[error("Podman error: {0}")]
|
||||
PodmanError(String),
|
||||
}
|
|
@ -18,6 +18,7 @@ use uuid::Uuid;
|
|||
mod cli;
|
||||
mod data;
|
||||
mod tests;
|
||||
mod errors;
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
@ -48,7 +49,7 @@ fn main() {
|
|||
}
|
||||
|
||||
fn run(config_path: String) {
|
||||
let config = config_from_file(config_path);
|
||||
let config = config_from_file(config_path).unwrap();
|
||||
|
||||
println!("{:#?}", config);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue