From b8b3c80be9f31e7230b0fc95f83bfee92eb41078 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Sat, 18 Jan 2020 22:20:17 -0800 Subject: [PATCH] Don't emit errors on critical path --- src/index/update.rs | 2 +- src/metadata.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/index/update.rs b/src/index/update.rs index f207b1b..35ee181 100644 --- a/src/index/update.rs +++ b/src/index/update.rs @@ -144,7 +144,7 @@ impl IndexUpdater { } if let Some(file_path_string) = file_path.to_str() { - if let Ok(tags) = metadata::read(file_path.as_path()) { + if let Some(tags) = metadata::read(file_path.as_path()) { if tags.year.is_some() { inconsistent_directory_year |= directory_year.is_some() && directory_year != tags.year; diff --git a/src/metadata.rs b/src/metadata.rs index 033530a..b31794b 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -2,6 +2,7 @@ use anyhow::*; use ape; use id3; use lewton::inside_ogg::OggStreamReader; +use log::error; use metaflac; use mp3_duration; use regex::Regex; @@ -24,13 +25,21 @@ pub struct SongTags { } #[cfg_attr(feature = "profile-index", flame)] -pub fn read(path: &Path) -> Result { - match utils::get_audio_format(path) { - Some(AudioFormat::FLAC) => read_flac(path), - Some(AudioFormat::MP3) => read_id3(path), - Some(AudioFormat::MPC) => read_ape(path), - Some(AudioFormat::OGG) => read_vorbis(path), - _ => bail!("Unsupported file format for reading metadata"), +pub fn read(path: &Path) -> Option { + let data = match utils::get_audio_format(path) { + Some(AudioFormat::FLAC) => Some(read_flac(path)), + Some(AudioFormat::MP3) => Some(read_id3(path)), + Some(AudioFormat::MPC) => Some(read_ape(path)), + Some(AudioFormat::OGG) => Some(read_vorbis(path)), + _ => None, + }; + match data { + Some(Ok(d)) => Some(d), + Some(Err(e)) => { + error!("Error while reading file metadata for '{:?}': {}", path, e); + None + } + None => None, } }