summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-07-24 19:42:57 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-07-24 19:42:57 +0200
commit31fc51f5beb12a49a469f0a4aa55831ad0fa473d (patch)
treebbb162383a2d626ded6abccda7b4255dedb735be
parentc4f8c289147f26fa424692c30d656322c0a2e1e3 (diff)
Make error printing show the whole chain of errors
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/main_view.rs3
-rw-r--r--src/util.rs14
2 files changed, 16 insertions, 1 deletions
diff --git a/src/main_view.rs b/src/main_view.rs
index 6950c9f..868efb1 100644
--- a/src/main_view.rs
+++ b/src/main_view.rs
@@ -119,6 +119,7 @@ impl MainView {
fn add_notmuch_query_layer(siv: &mut Cursive) {
use crate::util::dialog_for;
+ use crate::util::error_dialog_for;
let edit_view = EditView::new()
.on_submit(move |siv: &mut Cursive, query: &str| {
@@ -146,7 +147,7 @@ impl MainView {
})
.unwrap_or_else(|e: anyhow::Error| {
siv.pop_layer();
- siv.add_layer(dialog_for(e))
+ siv.add_layer(error_dialog_for(e))
});
})
.with_name("query");
diff --git a/src/util.rs b/src/util.rs
index fcb4432..3490e30 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,5 +1,6 @@
use cursive::views::Dialog;
use cursive::views::TextView;
+use anyhow::Error;
pub fn dialog_for<S: ToString>(e: S) -> Dialog {
Dialog::around({
@@ -9,3 +10,16 @@ pub fn dialog_for<S: ToString>(e: S) -> Dialog {
s.pop_layer();
})
}
+
+pub fn error_dialog_for(e: Error) -> Dialog {
+ let s = e.chain()
+ .rev()
+ .enumerate()
+ .map(|(i, e)| format!("{}: {}", i, e))
+ .fold(String::new(), |acc, s| {
+ acc + &s + "\n"
+ });
+
+ dialog_for(s)
+}
+