From 5ee6a679c5ef11cb2983230a1dfd66300f7e20f2 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Thu, 16 Oct 2025 11:53:06 +0200 Subject: [PATCH] Revert "add tracing + custom error type" This reverts commit 4702017914549bd23490a14fa235791c15f21788. --- Cargo.lock | 13 ------------- Cargo.toml | 1 - src/lib.rs | 37 ++++++++++--------------------------- src/web.rs | 4 +--- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 183abb9..1cd060b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -726,7 +726,6 @@ dependencies = [ "serde_json", "thiserror", "tokio", - "tracing", ] [[package]] @@ -1292,21 +1291,9 @@ checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" version = "0.1.34" diff --git a/Cargo.toml b/Cargo.toml index b20798f..a13c63c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,3 @@ serde_json = "1" chrono = "0.4" quick-xml = "0.38" thiserror = "2" -tracing = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 8a27f13..bd894e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ use serde_json::Value; use std::sync::Arc; use thiserror::Error; use tokio::{net::TcpListener, sync::RwLock}; -use tracing::warn; pub async fn start( title: String, @@ -27,15 +26,10 @@ pub async fn start( } #[derive(Error, Debug)] -enum FetchError { - #[error("error fetching url")] - Fetching(reqwest::Error), - #[error("error parsing json")] - JsonParsing(reqwest::Error), -} +enum FetchError {} trait Feed { - async fn fetch(&mut self) -> Result<(), FetchError>; + async fn fetch(&mut self) -> Result<(), Box>; } #[cfg(test)] @@ -75,7 +69,7 @@ impl rss::ToRss for TestFeed { #[cfg(test)] impl Feed for TestFeed { - async fn fetch(&mut self) -> Result<(), FetchError> { + async fn fetch(&mut self) -> Result<(), Box> { self.amount_fetch_calls += 1; Ok(()) } @@ -90,7 +84,7 @@ struct LiveFeed { } impl Feed for LiveFeed { - async fn fetch(&mut self) -> Result<(), FetchError> { + async fn fetch(&mut self) -> Result<(), Box> { let broadcasts = self.get_all_broadcasts().await?; for broadcast in broadcasts { @@ -138,17 +132,12 @@ impl LiveFeed { self.episodes.iter().any(|e| e.url == url) } - async fn get_all_broadcasts(&self) -> Result, FetchError> { + async fn get_all_broadcasts(&self) -> Result, Box> { // List of broadcasts: https://audioapi.orf.at/oe1/api/json/current/broadcasts // // ^ contains link, e.g. https://audioapi.orf.at/oe1/api/json/4.0/broadcast/797577/20250611 let url = "https://audioapi.orf.at/oe1/api/json/current/broadcasts"; - let data: Value = reqwest::get(url) - .await - .map_err(FetchError::Fetching)? - .json() - .await - .map_err(FetchError::JsonParsing)?; + let data: Value = reqwest::get(url).await?.json().await?; let mut ret: Vec = Vec::new(); @@ -156,19 +145,13 @@ impl LiveFeed { for day in days { if let Some(broadcasts) = day["broadcasts"].as_array() { for broadcast in broadcasts { - let Some(title) = broadcast["title"].as_str() else { - warn!("Broadcast has no 'title' attribute, skipping broadcast"); - continue; - }; - let Some(href) = broadcast["href"].as_str() else { - warn!("Broadcast has no 'href' attribute, skipping broadcast"); - continue; - }; if self.filter_titles.is_empty() - || self.filter_titles.contains(&title.into()) + || self + .filter_titles + .contains(&broadcast["title"].as_str().unwrap().into()) { { - ret.push(href.into()); + ret.push(broadcast["href"].as_str().unwrap().into()); } } } diff --git a/src/web.rs b/src/web.rs index 9fdcf74..076b611 100644 --- a/src/web.rs +++ b/src/web.rs @@ -4,9 +4,7 @@ use reqwest::header; use std::sync::Arc; use tokio::{net::TcpListener, sync::RwLock}; -async fn stream_handler( - State(state): State>>, -) -> impl IntoResponse { +async fn stream_handler(State(state): State>>) -> impl IntoResponse { state.write().await.fetch().await.unwrap(); let content = state.read().await.to_rss();