this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

combine errors when scrobbling a log file

+50 -9
+1 -1
src/error.rs
··· 30 30 #[error("parse: {0}")] 31 31 Parse(String), 32 32 33 - #[error("unknown: {0}")] 33 + #[error("{0}")] 34 34 Other(#[from] Box<dyn std::error::Error + Send + Sync>), 35 35 } 36 36
+3 -3
src/main.rs
··· 277 277 } 278 278 279 279 fn print_error(e: &OnyxError) { 280 - println!("{} {}", "error:".red().bold(), e); 280 + println!("{}: {}", "error".red().bold(), e); 281 281 } 282 282 283 283 fn handle_error(e: OnyxError) { ··· 285 285 OnyxError::Auth(_) => { 286 286 print_error(&e); 287 287 println!( 288 - "{} try logging in with '{}'", 289 - "hint:".green().bold(), 288 + "{}: try logging in with '{}'", 289 + "hint".green().bold(), 290 290 "onyx auth login".cyan().bold() 291 291 ); 292 292 }
+46 -5
src/scrobble.rs
··· 4 4 use jacquard::smol_str::ToSmolStr; 5 5 use jacquard::{CowStr, types::string::Datetime}; 6 6 use jacquard_api::fm_teal::alpha::feed::{Artist, play::Play}; 7 + use owo_colors::OwoColorize; 7 8 9 + use crate::print_error; 8 10 use crate::{ 9 11 LogFormat, 10 12 auth::GenericSession, ··· 95 97 96 98 pub async fn scrobble_track(&self, track: ParsedTrack) -> Result<(), OnyxError> { 97 99 let name = track.track_name.clone(); 98 - let play = self.generate_play(track); 99 - let _ = self.agent.create_record(play, None).await?; 100 - println!("[✓] {}", name); 100 + 101 + let res = async { 102 + let play = self.generate_play(track); 103 + self.agent.create_record(play, None).await 104 + } 105 + .await; 106 + 107 + if let Err(e) = res { 108 + println!("{} {}", "[✗]".red().bold(), name); 109 + return Err(OnyxError::Other(format!("{}, for '{}'", e, name).into())); 110 + } else { 111 + println!("{} {}", "[✓]".green().bold(), name); 112 + } 113 + 101 114 Ok(()) 102 115 } 103 116 ··· 106 119 path: PathBuf, 107 120 format: LogFormat, 108 121 ) -> Result<(), OnyxError> { 122 + println!( 123 + "{} {}", 124 + "scrobbling log:".dimmed(), 125 + path.to_str().unwrap().dimmed() 126 + ); 127 + 109 128 let tracks = match format { 110 129 LogFormat::AudioScrobbler => <AudioScrobblerParser as LogParser>::parse(path.clone()), 111 130 }?; 131 + 132 + let mut errors = Vec::new(); 112 133 113 134 for track in tracks { 114 - self.scrobble_track(track).await?; 135 + if let Err(e) = self.scrobble_track(track).await { 136 + errors.push(e); 137 + } 115 138 } 116 139 117 - println!("\n[✓] {}", path.to_str().unwrap()); 140 + if !errors.is_empty() { 141 + println!("\n{}:", "errors".red().bold()); 142 + 143 + for error in errors { 144 + println!(" - {}", error); 145 + } 146 + 147 + println!(); 148 + 149 + return Err(OnyxError::Other( 150 + format!( 151 + "failed to scrobble log file {}, see errors above", 152 + path.to_str().unwrap() 153 + ) 154 + .into(), 155 + )); 156 + } else { 157 + println!(); 158 + } 118 159 119 160 Ok(()) 120 161 }