Skip to content

Commit 033ff65

Browse files
committed
refactor: extract message cleaning logic
1 parent 326bea5 commit 033ff65

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/app.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,14 @@ impl LogViewerApp {
306306
}
307307
LoadingStatus::Failed(err_msg) => {
308308
let msg = format!("Loading failed: {err_msg}");
309-
let msg = msg.replace(r"\n", "\n");
310-
let msg = msg.replace(r#"\""#, "\"");
311309
if ui.button("Clear Error Status").clicked() {
312310
self.loading_status = LoadingStatus::NotInProgress;
313311
}
314312
ui.colored_label(ui.visuals().error_fg_color, msg);
315313
}
316314
LoadingStatus::Success(data) => {
317315
self.loading_status =
316+
// TODO 1: Make a copy of the loading type desired and match on it to get the data to load
318317
match Data::try_from((self.row_idx_field_name.as_ref(), &data[..])) {
319318
Ok(mut data) => {
320319
if let Some(old_data) = self.data.as_mut() {
@@ -332,7 +331,7 @@ impl LogViewerApp {
332331
}
333332
LoadingStatus::NotInProgress
334333
}
335-
Err(e) => LoadingStatus::Failed(format!("{e:?}")),
334+
Err(e) => LoadingStatus::Failed(clean_msg(format!("{e:?}"))),
336335
}
337336
}
338337
}
@@ -856,3 +855,7 @@ fn with_separators(value: usize) -> String {
856855
.unwrap()
857856
.join(",")
858857
}
858+
859+
fn clean_msg<S: AsRef<str>>(msg: S) -> String {
860+
msg.as_ref().replace(r"\n", "\n").replace(r#"\""#, "\"")
861+
}

0 commit comments

Comments
 (0)