Skip to content

Commit 0aec38b

Browse files
committed
refactor: use Rust 2021 format strings for error and debug messages
1 parent fdd4a16 commit 0aec38b

4 files changed

Lines changed: 32 additions & 39 deletions

File tree

examples/play.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn main() {
3636
println!("Connecting...");
3737
let session = Session::new(session_config, None);
3838
if let Err(e) = session.connect(credentials, false).await {
39-
println!("Error connecting: {}", e);
39+
println!("Error connecting: {e}");
4040
exit(1);
4141
}
4242

examples/playlist_tracks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ async fn main() {
2929

3030
let session = Session::new(session_config, None);
3131
if let Err(e) = session.connect(credentials, false).await {
32-
println!("Error connecting: {}", e);
32+
println!("Error connecting: {e}");
3333
exit(1);
3434
}
3535

3636
let plist = Playlist::get(&session, &plist_uri).await.unwrap();
37-
println!("{:?}", plist);
37+
println!("{plist:?}");
3838
for track_id in plist.tracks() {
3939
let plist_track = Track::get(&session, track_id).await.unwrap();
4040
println!("track: {} ", plist_track.name);

src/main.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ fn get_setup() -> Setup {
11141114
let tmp_dir = opt_str(TEMP_DIR).map_or(SessionConfig::default().tmp_dir, |p| {
11151115
let tmp_dir = PathBuf::from(p);
11161116
if let Err(e) = create_dir_all(&tmp_dir) {
1117-
error!("could not create or access specified tmp directory: {}", e);
1117+
error!("could not create or access specified tmp directory: {e}");
11181118
exit(1);
11191119
}
11201120
tmp_dir
@@ -1164,15 +1164,14 @@ fn get_setup() -> Setup {
11641164

11651165
if audio_dir.is_none() && opt_present(CACHE_SIZE_LIMIT) {
11661166
warn!(
1167-
"Without a `--{}` / `-{}` path, and/or if the `--{}` / `-{}` flag is set, `--{}` / `-{}` has no effect.",
1168-
CACHE, CACHE_SHORT, DISABLE_AUDIO_CACHE, DISABLE_AUDIO_CACHE_SHORT, CACHE_SIZE_LIMIT, CACHE_SIZE_LIMIT_SHORT
1167+
"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."
11691168
);
11701169
}
11711170

11721171
let cache = match Cache::new(cred_dir.clone(), volume_dir, audio_dir, limit) {
11731172
Ok(cache) => Some(cache),
11741173
Err(e) => {
1175-
warn!("Cannot create cache: {}", e);
1174+
warn!("Cannot create cache: {e}");
11761175
None
11771176
}
11781177
};
@@ -1240,8 +1239,7 @@ fn get_setup() -> Setup {
12401239
let oauth_port = if opt_present(OAUTH_PORT) {
12411240
if !enable_oauth {
12421241
warn!(
1243-
"Without the `--{}` / `-{}` flag set `--{}` / `-{}` has no effect.",
1244-
ENABLE_OAUTH, ENABLE_OAUTH_SHORT, OAUTH_PORT, OAUTH_PORT_SHORT
1242+
"Without the `--{ENABLE_OAUTH}` / `-{ENABLE_OAUTH_SHORT}` flag set `--{OAUTH_PORT}` / `-{OAUTH_PORT_SHORT}` has no effect."
12451243
);
12461244
}
12471245
opt_str(OAUTH_PORT)
@@ -1268,8 +1266,7 @@ fn get_setup() -> Setup {
12681266
if let Some(reason) = no_discovery_reason.as_deref() {
12691267
if opt_present(ZEROCONF_PORT) {
12701268
warn!(
1271-
"With {} `--{}` / `-{}` has no effect.",
1272-
reason, ZEROCONF_PORT, ZEROCONF_PORT_SHORT
1269+
"With {reason} `--{ZEROCONF_PORT}` / `-{ZEROCONF_PORT_SHORT}` has no effect."
12731270
);
12741271
}
12751272
}
@@ -1348,8 +1345,7 @@ fn get_setup() -> Setup {
13481345
if let Some(reason) = no_discovery_reason.as_deref() {
13491346
if opt_present(ZEROCONF_BACKEND) {
13501347
warn!(
1351-
"With {} `--{}` / `-{}` has no effect.",
1352-
reason, ZEROCONF_BACKEND, ZEROCONF_BACKEND_SHORT
1348+
"With {reason} `--{ZEROCONF_BACKEND}` / `-{ZEROCONF_BACKEND_SHORT}` has no effect."
13531349
);
13541350
}
13551351
}
@@ -1534,7 +1530,7 @@ fn get_setup() -> Setup {
15341530
url
15351531
},
15361532
Err(e) => {
1537-
error!("Invalid proxy URL: \"{}\", only URLs in the format \"http(s)://host:port\" are allowed", e);
1533+
error!("Invalid proxy URL: \"{e}\", only URLs in the format \"http(s)://host:port\" are allowed");
15381534
exit(1);
15391535
}
15401536
}
@@ -1591,8 +1587,7 @@ fn get_setup() -> Setup {
15911587
] {
15921588
if opt_present(a) {
15931589
warn!(
1594-
"Without the `--{}` / `-{}` flag normalisation options have no effect.",
1595-
ENABLE_VOLUME_NORMALISATION, ENABLE_VOLUME_NORMALISATION_SHORT,
1590+
"Without the `--{ENABLE_VOLUME_NORMALISATION}` / `-{ENABLE_VOLUME_NORMALISATION_SHORT}` flag normalisation options have no effect.",
15961591
);
15971592
break;
15981593
}
@@ -1774,7 +1769,7 @@ fn get_setup() -> Setup {
17741769
"none" => None,
17751770
_ => match format {
17761771
AudioFormat::F64 | AudioFormat::F32 => {
1777-
error!("Dithering is not available with format: {:?}.", format);
1772+
error!("Dithering is not available with format: {format:?}.");
17781773
exit(1);
17791774
}
17801775
_ => Some(dither::find_ditherer(ditherer_name).unwrap_or_else(|| {
@@ -1987,7 +1982,7 @@ async fn main() {
19871982

19881983
if let Some(spirc) = spirc.take() {
19891984
if let Err(e) = spirc.shutdown() {
1990-
error!("error sending spirc shutdown message: {}", e);
1985+
error!("error sending spirc shutdown message: {e}");
19911986
}
19921987
}
19931988
if let Some(spirc_task) = spirc_task.take() {
@@ -2021,7 +2016,7 @@ async fn main() {
20212016
mixer.clone()).await {
20222017
Ok((spirc_, spirc_task_)) => (spirc_, spirc_task_),
20232018
Err(e) => {
2024-
error!("could not initialize spirc: {}", e);
2019+
error!("could not initialize spirc: {e}");
20252020
exit(1);
20262021
}
20272022
};
@@ -2073,7 +2068,7 @@ async fn main() {
20732068
// Shutdown spirc if necessary
20742069
if let Some(spirc) = spirc {
20752070
if let Err(e) = spirc.shutdown() {
2076-
error!("error sending spirc shutdown message: {}", e);
2071+
error!("error sending spirc shutdown message: {e}");
20772072
}
20782073

20792074
if let Some(spirc_task) = spirc_task {

src/player_event_handler.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl EventHandler {
2828
PlayerEvent::TrackChanged { audio_item } => {
2929
match audio_item.track_id.to_base62() {
3030
Err(e) => {
31-
warn!("PlayerEvent::TrackChanged: Invalid track id: {}", e)
31+
warn!("PlayerEvent::TrackChanged: Invalid track id: {e}")
3232
}
3333
Ok(id) => {
3434
env_vars.insert("PLAYER_EVENT", "track_changed".to_string());
@@ -94,7 +94,7 @@ impl EventHandler {
9494
}
9595
}
9696
PlayerEvent::Stopped { track_id, .. } => match track_id.to_base62() {
97-
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {}", e),
97+
Err(e) => warn!("PlayerEvent::Stopped: Invalid track id: {e}"),
9898
Ok(id) => {
9999
env_vars.insert("PLAYER_EVENT", "stopped".to_string());
100100
env_vars.insert("TRACK_ID", id);
@@ -105,7 +105,7 @@ impl EventHandler {
105105
position_ms,
106106
..
107107
} => match track_id.to_base62() {
108-
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {}", e),
108+
Err(e) => warn!("PlayerEvent::Playing: Invalid track id: {e}"),
109109
Ok(id) => {
110110
env_vars.insert("PLAYER_EVENT", "playing".to_string());
111111
env_vars.insert("TRACK_ID", id);
@@ -117,22 +117,22 @@ impl EventHandler {
117117
position_ms,
118118
..
119119
} => match track_id.to_base62() {
120-
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {}", e),
120+
Err(e) => warn!("PlayerEvent::Paused: Invalid track id: {e}"),
121121
Ok(id) => {
122122
env_vars.insert("PLAYER_EVENT", "paused".to_string());
123123
env_vars.insert("TRACK_ID", id);
124124
env_vars.insert("POSITION_MS", position_ms.to_string());
125125
}
126126
},
127127
PlayerEvent::Loading { track_id, .. } => match track_id.to_base62() {
128-
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {}", e),
128+
Err(e) => warn!("PlayerEvent::Loading: Invalid track id: {e}"),
129129
Ok(id) => {
130130
env_vars.insert("PLAYER_EVENT", "loading".to_string());
131131
env_vars.insert("TRACK_ID", id);
132132
}
133133
},
134134
PlayerEvent::Preloading { track_id, .. } => match track_id.to_base62() {
135-
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {}", e),
135+
Err(e) => warn!("PlayerEvent::Preloading: Invalid track id: {e}"),
136136
Ok(id) => {
137137
env_vars.insert("PLAYER_EVENT", "preloading".to_string());
138138
env_vars.insert("TRACK_ID", id);
@@ -141,8 +141,7 @@ impl EventHandler {
141141
PlayerEvent::TimeToPreloadNextTrack { track_id, .. } => {
142142
match track_id.to_base62() {
143143
Err(e) => warn!(
144-
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {}",
145-
e
144+
"PlayerEvent::TimeToPreloadNextTrack: Invalid track id: {e}"
146145
),
147146
Ok(id) => {
148147
env_vars.insert("PLAYER_EVENT", "preload_next".to_string());
@@ -151,14 +150,14 @@ impl EventHandler {
151150
}
152151
}
153152
PlayerEvent::EndOfTrack { track_id, .. } => match track_id.to_base62() {
154-
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {}", e),
153+
Err(e) => warn!("PlayerEvent::EndOfTrack: Invalid track id: {e}"),
155154
Ok(id) => {
156155
env_vars.insert("PLAYER_EVENT", "end_of_track".to_string());
157156
env_vars.insert("TRACK_ID", id);
158157
}
159158
},
160159
PlayerEvent::Unavailable { track_id, .. } => match track_id.to_base62() {
161-
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {}", e),
160+
Err(e) => warn!("PlayerEvent::Unavailable: Invalid track id: {e}"),
162161
Ok(id) => {
163162
env_vars.insert("PLAYER_EVENT", "unavailable".to_string());
164163
env_vars.insert("TRACK_ID", id);
@@ -173,7 +172,7 @@ impl EventHandler {
173172
position_ms,
174173
..
175174
} => match track_id.to_base62() {
176-
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {}", e),
175+
Err(e) => warn!("PlayerEvent::Seeked: Invalid track id: {e}"),
177176
Ok(id) => {
178177
env_vars.insert("PLAYER_EVENT", "seeked".to_string());
179178
env_vars.insert("TRACK_ID", id);
@@ -186,7 +185,7 @@ impl EventHandler {
186185
..
187186
} => match track_id.to_base62() {
188187
Err(e) => {
189-
warn!("PlayerEvent::PositionCorrection: Invalid track id: {}", e)
188+
warn!("PlayerEvent::PositionCorrection: Invalid track id: {e}")
190189
}
191190
Ok(id) => {
192191
env_vars.insert("PLAYER_EVENT", "position_correction".to_string());
@@ -263,7 +262,7 @@ impl Drop for EventHandler {
263262
debug!("Shutting down EventHandler thread ...");
264263
if let Some(handle) = self.thread_handle.take() {
265264
if let Err(e) = handle.join() {
266-
error!("EventHandler thread Error: {:?}", e);
265+
error!("EventHandler thread Error: {e:?}");
267266
}
268267
}
269268
}
@@ -289,24 +288,23 @@ fn run_program(env_vars: HashMap<&str, String>, onevent: &str) {
289288
let mut v: Vec<&str> = onevent.split_whitespace().collect();
290289

291290
debug!(
292-
"Running {} with environment variables:\n{:#?}",
293-
onevent, env_vars
291+
"Running {onevent} with environment variables:\n{env_vars:#?}"
294292
);
295293

296294
match Command::new(v.remove(0))
297295
.args(&v)
298296
.envs(env_vars.iter())
299297
.spawn()
300298
{
301-
Err(e) => warn!("On event program {} failed to start: {}", onevent, e),
299+
Err(e) => warn!("On event program {onevent} failed to start: {e}"),
302300
Ok(mut child) => match child.wait() {
303-
Err(e) => warn!("On event program {} failed: {}", onevent, e),
301+
Err(e) => warn!("On event program {onevent} failed: {e}"),
304302
Ok(e) if e.success() => (),
305303
Ok(e) => {
306304
if let Some(code) = e.code() {
307-
warn!("On event program {} returned exit code {}", onevent, code);
305+
warn!("On event program {onevent} returned exit code {code}");
308306
} else {
309-
warn!("On event program {} returned failure: {}", onevent, e);
307+
warn!("On event program {onevent} returned failure: {e}");
310308
}
311309
}
312310
},

0 commit comments

Comments
 (0)