From 4cd168409fed9291c5872c5e2d584048592e46b4 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Thu, 2 May 2024 22:26:03 +0200 Subject: [PATCH] improve errors (put in path that was not writeable --- src/client.rs | 4 ++-- src/client/utils.rs | 18 +++++++++++------- src/errors.rs | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/client.rs b/src/client.rs index c0b9dfc..0318b53 100644 --- a/src/client.rs +++ b/src/client.rs @@ -97,7 +97,7 @@ impl SplitterClient { let split_info = utils::get_playlist_info(&split_playlist_path).await?; tokio::fs::remove_file(&split_playlist_path) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(split_playlist_path.clone(), e))?; trace!( "total duration: {} in {} parts", split_info.total_duration.to_string(), @@ -110,7 +110,7 @@ impl SplitterClient { debug!("removing original file: {:?}", input_path); tokio::fs::remove_file(&input_path) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(input_path.clone(), e))?; let duration = Instant::now().duration_since(start_time); info!("Done Splitting. Whole operation took: {:?}", duration); diff --git a/src/client/utils.rs b/src/client/utils.rs index b6bfcd4..c6ceb4c 100644 --- a/src/client/utils.rs +++ b/src/client/utils.rs @@ -84,7 +84,7 @@ async fn join_last_two_parts(input_parts: &mut PlaylistInfo, base_folder: &Path) ), ) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(join_txt_path.clone(), e))?; run_ffmpeg_concat( join_txt_path @@ -101,22 +101,26 @@ async fn join_last_two_parts(input_parts: &mut PlaylistInfo, base_folder: &Path) "removing files: {:?}, {:?}, {:?}", second_last_part.path, last_part.path, join_txt_path ); - tokio::fs::remove_file(last_part.path) + trace!("removing file: {:?}", last_part.path); + tokio::fs::remove_file(&last_part.path) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(last_part.path, e))?; + trace!("removing file: {:?}", second_last_part.path); tokio::fs::remove_file(&second_last_part.path) .await - .map_err(SplitterError::Write)?; - tokio::fs::remove_file(join_txt_path) + .map_err(|e| SplitterError::Write(second_last_part.path.clone(), e))?; + trace!("removing file: {:?}", join_txt_path); + tokio::fs::remove_file(&join_txt_path) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(join_txt_path.clone(), e))?; debug!( "renaming file: {:?} to {:?}", join_out_tmp_path, second_last_part.path ); tokio::fs::rename(join_out_tmp_path, &second_last_part.path) .await - .map_err(SplitterError::Write)?; + .map_err(|e| SplitterError::Write(second_last_part.path.clone(), e))?; + debug!("joined last two parts together"); Ok(()) } diff --git a/src/errors.rs b/src/errors.rs index c9bd9bb..25b569b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -19,7 +19,7 @@ pub enum SplitterError { #[error("Could not read from filesystem: {0:?}")] Read(#[source] io::Error), #[error("Could not write to filesystem: {0:?}")] - Write(#[source] io::Error), + Write(PathBuf, #[source] io::Error), #[error("Path could not be canonicalized: {0:?}")] Canonicalize(#[source] io::Error),