diff --git a/src/main.rs b/src/main.rs index bf7c136..848b49a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,7 +152,7 @@ async fn main() -> Result<()> { let mut cli = Cli::command(); generate(shell, &mut cli, "managarr", &mut io::stdout()) } - Command::TailLogs { no_color } => tail_logs(no_color).await, + Command::TailLogs { no_color } => tail_logs(no_color).await?, }, None => { let app_nw = Arc::clone(&app); diff --git a/src/network/sonarr_network/library/series/mod.rs b/src/network/sonarr_network/library/series/mod.rs index 800c58d..100a162 100644 --- a/src/network/sonarr_network/library/series/mod.rs +++ b/src/network/sonarr_network/library/series/mod.rs @@ -312,11 +312,7 @@ impl Network<'_, '_> { Route::Sonarr(ActiveSonarrBlock::SeriesHistorySortPrompt, _) ); - let series_history = app - .data - .sonarr_data - .series_history - .get_or_insert_default(); + let series_history = app.data.sonarr_data.series_history.get_or_insert_default(); if !is_sorting { history_vec.sort_by(|a, b| a.id.cmp(&b.id)); diff --git a/src/utils.rs b/src/utils.rs index d853e2f..3de6810 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Result; -use anyhow::anyhow; +use anyhow::{anyhow, Context}; use colored::Colorize; use indicatif::{ProgressBar, ProgressStyle}; -use log::{LevelFilter, error}; +use log::{error, LevelFilter}; use log4rs::append::file::FileAppender; use log4rs::config::{Appender, Root}; use log4rs::encode::pattern::PatternEncoder; @@ -18,7 +18,7 @@ use reqwest::{Certificate, Client}; use tokio::sync::Mutex; use tokio_util::sync::CancellationToken; -use crate::app::{App, AppConfig, log_and_print_error}; +use crate::app::{log_and_print_error, App, AppConfig}; use crate::cli::{self, Command}; use crate::network::Network; use crate::ui::theme::ThemeDefinitionsWrapper; @@ -79,16 +79,15 @@ pub fn convert_runtime(runtime: i64) -> (i64, i64) { (hours, minutes) } -pub async fn tail_logs(no_color: bool) { +pub async fn tail_logs(no_color: bool) -> Result<()> { let re = Regex::new(r"^(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+<(?P[^\s>]+)>\s+\[(?P[A-Z]+)]\s+(?P[^:]+):(?P\d+)\s+-\s+(?P.*)$").unwrap(); let file_path = get_log_path(); let file = File::open(&file_path).expect("Cannot open file"); let mut reader = BufReader::new(file); - if let Err(e) = reader.seek(SeekFrom::End(0)) { - eprintln!("Unable to tail log file: {e:?}"); - process::exit(1); - }; + reader + .seek(SeekFrom::End(0)) + .with_context(|| "Unable to tail log file")?; let mut lines = reader.lines(); @@ -104,8 +103,7 @@ pub async fn tail_logs(no_color: bool) { } } }) - .await - .unwrap(); + .await? } fn colorize_log_line(line: &str, re: &Regex) -> String {