add start of error handling
This commit is contained in:
parent
4cbd6fcf2b
commit
66424f704d
6 changed files with 1457 additions and 15 deletions
1421
Cargo.lock
generated
1421
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,9 +8,12 @@ readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
alphanumeric-sort = "1.5.3"
|
alphanumeric-sort = "1.5.3"
|
||||||
|
better-commands = "1.0.2"
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
clap_complete = "4.5.40"
|
clap_complete = "4.5.40"
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
|
sqlx = "0.8.3"
|
||||||
|
thiserror = "2.0.11"
|
||||||
toml = "0.8.19"
|
toml = "0.8.19"
|
||||||
uuid = { version = "1.11.0", features = ["v7", "fast-rng"] }
|
uuid = { version = "1.11.0", features = ["v7", "fast-rng"] }
|
||||||
|
|
||||||
|
|
14
podman-compose.example.yml
Normal file
14
podman-compose.example.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: 'docker.io/library/postgres:17-alpine'
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: 'ChangeMeeeeeeeeeeeeee'
|
||||||
|
# if there's already a he/him gregory down the hall, then change it to gregory_it_its, to make sure you know it's gregory, the program, not gregory the he/him down the hall
|
||||||
|
# ig if there's an it/its gregory already then they just have to change their name to Its Majesty Queen Henry the Eighth
|
||||||
|
# oops sorry it/its gregory down the hall, correction: it just has to changes its name
|
||||||
|
POSTGRES_USER: 'gregory'
|
||||||
|
POSTGRES_DB: 'gregory'
|
||||||
|
volumes:
|
||||||
|
- './gregory-pg:/var/lib/postgresql/data'
|
||||||
|
ports:
|
||||||
|
- '5432:5432'
|
16
src/data.rs
16
src/data.rs
|
@ -1,5 +1,6 @@
|
||||||
//! Data structs. used by gregory and stuff for handling them
|
//! Data structs. used by gregory and stuff for handling them
|
||||||
|
|
||||||
|
use crate::errors::Error;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::time;
|
use std::time;
|
||||||
use std::{collections::HashMap, fs, thread};
|
use std::{collections::HashMap, fs, thread};
|
||||||
|
@ -97,9 +98,18 @@ pub(crate) struct JobExitStatus {
|
||||||
pub(crate) container_name: String,
|
pub(crate) container_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn config_from_file(filename: String) -> Config {
|
pub(crate) fn config_from_file(filename: String) -> Result<Config, Error> {
|
||||||
let toml: Config = toml::from_str(fs::read_to_string(filename).unwrap().as_str()).unwrap();
|
match fs::read_to_string(filename) {
|
||||||
return toml;
|
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 cli;
|
||||||
mod data;
|
mod data;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
mod errors;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
@ -48,7 +49,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(config_path: String) {
|
fn run(config_path: String) {
|
||||||
let config = config_from_file(config_path);
|
let config = config_from_file(config_path).unwrap();
|
||||||
|
|
||||||
println!("{:#?}", config);
|
println!("{:#?}", config);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue