From da361d0cb93cd8edd076859b2c607509a96dac8d Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 4 Sep 2018 14:12:05 +0300 Subject: [PATCH] Pipeline: Avoid spamming stderr when not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit add a new DataError Variant for feeds that return 304. Its expected behaviror and the current API of Source::into_feed is kinda limiting the return type to make it easier to handle. Up till now 304 was returning an Error to early return. Ideally Source::into_feed will return a Multi variant Result Enum. example: enum FeedResult { Ok(Success(feed)), Ok(NotModified), Err(err), } Hopefully in a refactor in the near Futureā„¢ Till then we will just have to match and ignore DataError::FeedNotModified. --- podcasts-data/src/errors.rs | 2 ++ podcasts-data/src/models/source.rs | 5 ++++- podcasts-data/src/pipeline.rs | 9 +++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/podcasts-data/src/errors.rs b/podcasts-data/src/errors.rs index 1f34a8d..a75055f 100644 --- a/podcasts-data/src/errors.rs +++ b/podcasts-data/src/errors.rs @@ -65,6 +65,8 @@ pub enum DataError { HttpStatusGeneral(HttpStatusError), #[fail(display = "Source redirects to a new url")] FeedRedirect(Source), + #[fail(display = "Feed is up to date")] + FeedNotModified(Source), #[fail( display = "Error occured while Parsing an Episode. Reason: {}", reason diff --git a/podcasts-data/src/models/source.rs b/podcasts-data/src/models/source.rs index 672dc5e..9842ce4 100644 --- a/podcasts-data/src/models/source.rs +++ b/podcasts-data/src/models/source.rs @@ -144,7 +144,10 @@ impl Source { }; match code { - StatusCode::NotModified => return Err(self.make_err("304: skipping..", code)), + StatusCode::NotModified => { + info!("304: Source, (id: {}), is up to date", self.id()); + return Err(DataError::FeedNotModified(self)); + } StatusCode::MovedPermanently | StatusCode::Found | StatusCode::PermanentRedirect => { warn!("Feed was moved permanently."); self = self.update_url(&res)?; diff --git a/podcasts-data/src/pipeline.rs b/podcasts-data/src/pipeline.rs index f3202c8..6f2ab34 100644 --- a/podcasts-data/src/pipeline.rs +++ b/podcasts-data/src/pipeline.rs @@ -38,8 +38,13 @@ where }) // the stream will stop at the first error so // we ensure that everything will succeded regardless. - .map_err(|err| error!("Error: {}", err)) - .then(|_| ok::<(), DataError>(())) + .map_err(|err| { + match err { + // Avoid spamming the stderr when its not an eactual error + DataError::FeedNotModified(_) => (), + _ => error!("Error: {}", err), + } + }).then(|_| ok::<(), DataError>(())) .collect() }