1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

refactor: use Rust 2021 format strings for error and debug messages

This commit is contained in:
Roderick van Domburg 2025-08-13 15:44:58 +02:00
parent fdd4a16fdc
commit 0aec38b07a
No known key found for this signature in database
GPG key ID: 607FA06CB5236AE0
4 changed files with 32 additions and 39 deletions

View file

@ -36,7 +36,7 @@ async fn main() {
println!("Connecting...");
let session = Session::new(session_config, None);
if let Err(e) = session.connect(credentials, false).await {
println!("Error connecting: {}", e);
println!("Error connecting: {e}");
exit(1);
}

View file

@ -29,12 +29,12 @@ async fn main() {
let session = Session::new(session_config, None);
if let Err(e) = session.connect(credentials, false).await {
println!("Error connecting: {}", e);
println!("Error connecting: {e}");
exit(1);
}
let plist = Playlist::get(&session, &plist_uri).await.unwrap();
println!("{:?}", plist);
println!("{plist:?}");
for track_id in plist.tracks() {
let plist_track = Track::get(&session, track_id).await.unwrap();
println!("track: {} ", plist_track.name);

View file

@ -1114,7 +1114,7 @@ fn get_setup() -> Setup {
let tmp_dir = opt_str(TEMP_DIR).map_or(SessionConfig::default().tmp_dir, |p| {
let tmp_dir = PathBuf::from(p);
if let Err(e) = create_dir_all(&tmp_dir) {
error!("could not create or access specified tmp directory: {}", e);
error!("could not create or access specified tmp directory: {e}");
exit(1);
}
tmp_dir
@ -1164,15 +1164,14 @@ fn get_setup() -> Setup {
if audio_dir.is_none() && opt_present(CACHE_SIZE_LIMIT) {
warn!(
"Without a `--{}` / `-{}` path, and/or if the `--{}` / `-{}` flag is set, `--{}` / `-{}` has no effect.",
CACHE, CACHE_SHORT, DISABLE_AUDIO_CACHE, DISABLE_AUDIO_CACHE_SHORT, CACHE_SIZE_LIMIT, CACHE_SIZE_LIMIT_SHORT
"Without a `--{CACHE}` / `-{CACHE_SHORT}` path, and/or if the `--{DISABLE_AUDIO_CACHE}` / `-{DISABLE_AUDIO_CACHE_SHORT}` flag is set, `--{CACHE_SIZE_LIMIT}` / `-{CACHE_SIZE_LIMIT_SHORT}` has no effect."
);
}
let cache = match Cache::new(cred_dir.clone(), volume_dir, audio_dir, limit) {
Ok(cache) => Some(cache),
Err(e) => {
warn!("Cannot create cache: {}", e);
warn!("Cannot create cache: {e}");
None
}
};
@ -1240,8 +1239,7 @@ fn get_setup() -> Setup {
let oauth_port = if opt_present(OAUTH_PORT) {
if !enable_oauth {
warn!(
"Without the `--{}` / `-{}` flag set `--{}` / `-{}` has no effect.",
ENABLE_OAUTH, ENABLE_OAUTH_SHORT, OAUTH_PORT, OAUTH_PORT_SHORT
"Without the `--{ENABLE_OAUTH}` / `-{ENABLE_OAUTH_SHORT}` flag set `--{OAUTH_PORT}` / `-{OAUTH_PORT_SHORT}` has no effect."
);
}
opt_str(OAUTH_PORT)
@ -1268,8 +1266,7 @@ fn get_setup() -> Setup {
if let Some(reason) = no_discovery_reason.as_deref() {
if opt_present(ZEROCONF_PORT) {
warn!(
"With {} `--{}` / `-{}` has no effect.",
reason, ZEROCONF_PORT, ZEROCONF_PORT_SHORT
"With {reason} `--{ZEROCONF_PORT}` / `-{ZEROCONF_PORT_SHORT}` has no effect."
);
}
}
@ -1348,8 +1345,7 @@ fn get_setup() -> Setup {
if let Some(reason) = no_discovery_reason.as_deref() {
if opt_present(ZEROCONF_BACKEND) {
warn!(
"With {} `--{}` / `-{}` has no effect.",
reason, ZEROCONF_BACKEND, ZEROCONF_BACKEND_SHORT
"With {reason} `--{ZEROCONF_BACKEND}` / `-{ZEROCONF_BACKEND_SHORT}` has no effect."
);
}
}
@ -1534,7 +1530,7 @@ fn get_setup() -> Setup {
url
},
Err(e) => {
error!("Invalid proxy URL: \"{}\", only URLs in the format \"http(s)://host:port\" are allowed", e);
error!("Invalid proxy URL: \"{e}\", only URLs in the format \"http(s)://host:port\" are allowed");
exit(1);
}
}
@ -1591,8 +1587,7 @@ fn get_setup() -> Setup {
] {
if opt_present(a) {
warn!(
"Without the `--{}` / `-{}` flag normalisation options have no effect.",
ENABLE_VOLUME_NORMALISATION, ENABLE_VOLUME_NORMALISATION_SHORT,
"Without the `--{ENABLE_VOLUME_NORMALISATION}` / `-{ENABLE_VOLUME_NORMALISATION_SHORT}` flag normalisation options have no effect.",
);
break;
}
@ -1774,7 +1769,7 @@ fn get_setup() -> Setup {
"none" => None,
_ => match format {
AudioFormat::F64 | AudioFormat::F32 => {
error!("Dithering is not available with format: {:?}.", format);
error!("Dithering is not available with format: {format:?}.");
exit(1);
}
_ => Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
@ -1987,7 +1982,7 @@ async fn main() {
if let Some(spirc) = spirc.take() {
if let Err(e) = spirc.shutdown() {
error!("error sending spirc shutdown message: {}", e);
error!("error sending spirc shutdown message: {e}");
}
}
if let Some(spirc_task) = spirc_task.take() {
@ -2021,7 +2016,7 @@ async fn main() {
mixer.clone()).await {
Ok((spirc_, spirc_task_)) => (spirc_, spirc_task_),
Err(e) => {
error!("could not initialize spirc: {}", e);
error!("could not initialize spirc: {e}");
exit(1);
}
};
@ -2073,7 +2068,7 @@ async fn main() {
// Shutdown spirc if necessary
if let Some(spirc) = spirc {
if let Err(e) = spirc.shutdown() {
error!("error sending spirc shutdown message: {}", e);
error!("error sending spirc shutdown message: {e}");
}
if let Some(spirc_task) = spirc_task {

View file

@ -28,7 +28,7 @@ impl EventHandler {
PlayerEvent::TrackChanged { audio_item } => {
match audio_item.track_id.to_base62() {
Err(e) => {
warn!("PlayerEvent::TrackChanged: Invalid track id: {}", e)
warn!("PlayerEvent::TrackChanged: Invalid track id: {e}")
}
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "track_changed".to_string());
@ -94,7 +94,7 @@ impl EventHandler {
}
}
PlayerEvent::Stopped { track_id, .. } => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "stopped".to_string());
env_vars.insert("TRACK_ID", id);
@ -105,7 +105,7 @@ impl EventHandler {
position_ms,
..
} => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "playing".to_string());
env_vars.insert("TRACK_ID", id);
@ -117,7 +117,7 @@ impl EventHandler {
position_ms,
..
} => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "paused".to_string());
env_vars.insert("TRACK_ID", id);
@ -125,14 +125,14 @@ impl EventHandler {
}
},
PlayerEvent::Loading { track_id, .. } => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "loading".to_string());
env_vars.insert("TRACK_ID", id);
}
},
PlayerEvent::Preloading { track_id, .. } => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "preloading".to_string());
env_vars.insert("TRACK_ID", id);
@ -141,8 +141,7 @@ impl EventHandler {
PlayerEvent::TimeToPreloadNextTrack { track_id, .. } => {
match track_id.to_base62() {
Err(e) => warn!(
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {}",
e
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {e}"
),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "preload_next".to_string());
@ -151,14 +150,14 @@ impl EventHandler {
}
}
PlayerEvent::EndOfTrack { track_id, .. } => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "end_of_track".to_string());
env_vars.insert("TRACK_ID", id);
}
},
PlayerEvent::Unavailable { track_id, .. } => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "unavailable".to_string());
env_vars.insert("TRACK_ID", id);
@ -173,7 +172,7 @@ impl EventHandler {
position_ms,
..
} => match track_id.to_base62() {
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {}", e),
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {e}"),
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "seeked".to_string());
env_vars.insert("TRACK_ID", id);
@ -186,7 +185,7 @@ impl EventHandler {
..
} => match track_id.to_base62() {
Err(e) => {
warn!("PlayerEvent::PositionCorrection: Invalid track id: {}", e)
warn!("PlayerEvent::PositionCorrection: Invalid track id: {e}")
}
Ok(id) => {
env_vars.insert("PLAYER_EVENT", "position_correction".to_string());
@ -263,7 +262,7 @@ impl Drop for EventHandler {
debug!("Shutting down EventHandler thread ...");
if let Some(handle) = self.thread_handle.take() {
if let Err(e) = handle.join() {
error!("EventHandler thread Error: {:?}", e);
error!("EventHandler thread Error: {e:?}");
}
}
}
@ -289,8 +288,7 @@ fn run_program(env_vars: HashMap<&str, String>, onevent: &str) {
let mut v: Vec<&str> = onevent.split_whitespace().collect();
debug!(
"Running {} with environment variables:\n{:#?}",
onevent, env_vars
"Running {onevent} with environment variables:\n{env_vars:#?}"
);
match Command::new(v.remove(0))
@ -298,15 +296,15 @@ fn run_program(env_vars: HashMap<&str, String>, onevent: &str) {
.envs(env_vars.iter())
.spawn()
{
Err(e) => warn!("On event program {} failed to start: {}", onevent, e),
Err(e) => warn!("On event program {onevent} failed to start: {e}"),
Ok(mut child) => match child.wait() {
Err(e) => warn!("On event program {} failed: {}", onevent, e),
Err(e) => warn!("On event program {onevent} failed: {e}"),
Ok(e) if e.success() => (),
Ok(e) => {
if let Some(code) = e.code() {
warn!("On event program {} returned exit code {}", onevent, code);
warn!("On event program {onevent} returned exit code {code}");
} else {
warn!("On event program {} returned failure: {}", onevent, e);
warn!("On event program {onevent} returned failure: {e}");
}
}
},