Skip to content

Commit 2793b9c

Browse files
committed
gui representation of errors
1 parent 98393a7 commit 2793b9c

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ impl Wish {
149149
}
150150
}
151151

152+
pub fn raise_error(&self, message: &str, detail: &str) {
153+
self.predicates_window.withdraw();
154+
rstk::message_box()
155+
.parent(&self.window)
156+
.icon(IconImage::Error)
157+
.title("Unexpected Error")
158+
.message(message)
159+
.detail(detail)
160+
.show();
161+
rstk::end_wish();
162+
}
163+
152164
fn build_predicates_window(&mut self) {
153165
self.predicates_window.resizable(false, false);
154166
self.predicates_window.background("#dedddd");
@@ -420,10 +432,6 @@ impl Frontend for Wish {
420432
}
421433

422434
fn display(&self) {
423-
if self.input == "_exit_" {
424-
rstk::end_wish();
425-
}
426-
427435
let page_size = std::cmp::min(self.page_size, self.predicates.len());
428436
let texts: Vec<String> = self
429437
.predicates

src/main.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ struct Args {
2121
fn main() {
2222
let args = Args::parse();
2323

24-
let clafrica_conf = ClafricaConfig::from_file(&args.config_file).unwrap_or_else(|err| {
25-
eprintln!("Problem parsing config file: {err}");
26-
process::exit(1);
27-
});
28-
2924
let wish_conf = WishConfig::from_file(&args.config_file).unwrap_or_else(|err| {
3025
eprintln!("Problem parsing config file: {err}");
3126
process::exit(1);
@@ -37,9 +32,16 @@ fn main() {
3732
// We start the backend
3833
{
3934
let frontend = frontend.clone();
35+
4036
thread::spawn(move || {
41-
if let Err(e) = run(clafrica_conf, frontend) {
42-
eprintln!("Application error: {e}");
37+
let clafrica_conf =
38+
ClafricaConfig::from_file(&args.config_file).unwrap_or_else(|err| {
39+
frontend.raise_error("Problem parsing config file", &err.to_string());
40+
process::exit(1);
41+
});
42+
43+
if let Err(e) = run(clafrica_conf, frontend.clone()) {
44+
frontend.raise_error("Application error", &e.to_string());
4345
process::exit(1);
4446
}
4547
});

0 commit comments

Comments
 (0)