() -> anyhow::result<()>

pull/14/head
prplV 2024-12-11 13:11:15 +03:00
parent 2d225f4c09
commit e7817a97b6
2 changed files with 12 additions and 14 deletions

View File

@ -1,6 +1,7 @@
mod options; mod options;
mod utils; mod utils;
use anyhow::Error;
use clap::Parser; use clap::Parser;
use log::{error, info}; use log::{error, info};
use options::config::*; use options::config::*;
@ -17,12 +18,12 @@ use utils::*;
use options::preboot::PrebootParams; use options::preboot::PrebootParams;
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() { async fn main() -> anyhow::Result<()>{
let preboot = PrebootParams::parse().validate(); let preboot = PrebootParams::parse().validate()?;
if let Err(_) = preboot { // if let Err(_) = preboot {
return; // return;
} // }
let _ = setup_logger(); let _ = setup_logger();
@ -32,7 +33,7 @@ async fn main() {
// then conf checks to choose the most actual \ // then conf checks to choose the most actual \
let processes: Processes = get_actual_config().await.unwrap_or_else(|| { let processes: Processes = get_actual_config().await.unwrap_or_else(|| {
error!("No actual configuration for runner. Stopping..."); error!("No actual configuration for runner. Stopping...");
std::process::exit(101); std::process::exit(1);
}); });
info!( info!(
@ -43,7 +44,7 @@ async fn main() {
if processes.processes.is_empty() { if processes.processes.is_empty() {
error!("Processes list is null, runner-rs initialization is stopped"); error!("Processes list is null, runner-rs initialization is stopped");
return; return Err(Error::msg("Empty processes segment in config"));
} }
let mut handler: Vec<tokio::task::JoinHandle<()>> = vec![]; let mut handler: Vec<tokio::task::JoinHandle<()>> = vec![];
// is in need to send to the signals handler thread // is in need to send to the signals handler thread
@ -97,7 +98,7 @@ async fn main() {
for i in handler { for i in handler {
let _ = i.await; let _ = i.await;
} }
return; Ok(())
} }
// todo: integration tests // todo: integration tests

View File

@ -104,18 +104,15 @@ pub struct PrebootParams {
impl PrebootParams { impl PrebootParams {
pub fn validate(self) -> Result<Self> { pub fn validate(self) -> Result<Self> {
if !self.socket_path.exists() { if !self.socket_path.exists() {
eprintln!("Socket-file {} doesn't exist. Cannot start", &self.socket_path.display()); return Err(Error::msg("Socket-file not found or Noxis can't read it. Cannot start"));
return Err(Error::msg("Socket-file Not Found"));
} }
// existing log dir // existing log dir
if !self.log_to.exists() { if !self.log_to.exists() {
eprintln!("Log directory {} doesn't exist", &self.log_to.display()); return Err(Error::msg("Log Directory Not Found or Noxis can't read it. Cannot start"));
return Err(Error::msg("Log Directory Not Found. Cannot start"));
} }
// existing sock file // existing sock file
if !self.config.exists() { if !self.config.exists() {
eprintln!("Local config file {} doesn't exist", &self.config.display()); return Err(Error::msg("Local Config Not Found or Noxis can't read it. Cannot start"));
return Err(Error::msg("Local Config Not Found. Cannot start"));
} }
// redis server check // redis server check
Ok(self) Ok(self)