From 9f15f4cbd6170ac5bc2ce158e1f9a588bcefce4d Mon Sep 17 00:00:00 2001 From: KeksNino Date: Tue, 1 Sep 2026 11:20:33 +0200 Subject: [PATCH] refactor: remove voiding of return values when calling functions + properly handle errors for individual files SUGGESTIONS BY AI --- src/main.rs | 10 +++++++--- src/move_files.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 95a45a4..be33398 100755 --- a/src/main.rs +++ b/src/main.rs @@ -51,12 +51,16 @@ fn main() -> Result<(), Box> { continue; } let tag = get_metadata(&path); - let _ = move_files(path, tag.clone(), extra_files.clone(), *copy); + if let Err(e) = + move_files(path.clone(), tag.clone(), extra_files.clone(), *copy) + { + eprintln!("Failed to import {:?}: {}", path, e); + } } } else { println!("Importing file: {:?}", file); let tag = get_metadata(file); - let _ = move_files(file.clone(), tag.clone(), extra_files, *copy); + move_files(file.clone(), tag.clone(), extra_files, *copy)?; } } Commands::Show { file } => { @@ -70,7 +74,7 @@ fn main() -> Result<(), Box> { Commands::Edit { file } => { let path = PathBuf::from("/tmp/keks-sort-metadata"); let tag = get_metadata(file); - let _ = edit(path, tag); + edit(path, tag)?; } } diff --git a/src/move_files.rs b/src/move_files.rs index 9d7ff7e..d038883 100644 --- a/src/move_files.rs +++ b/src/move_files.rs @@ -2,7 +2,7 @@ use glob::glob; use lofty::prelude::ItemKey; use lofty::tag::Accessor; use lofty::tag::Tag; -use std::fs::{copy, create_dir_all, rename}; +use std::fs::{copy, create_dir_all, remove_dir, rename}; use std::path::PathBuf; pub fn move_files( @@ -32,7 +32,7 @@ pub fn move_files( }; let dir_to_create = target_dir.join(artist_dir).join(album_dir.as_ref()); - let _ = create_dir_all(dir_to_create); + create_dir_all(&dir_to_create)?; let target = target_dir.join(artist_dir).join(album_dir.as_ref()); let file_name = PathBuf::from(format!(