diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-07-24 19:42:57 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-07-24 19:42:57 +0200 |
commit | 31fc51f5beb12a49a469f0a4aa55831ad0fa473d (patch) | |
tree | bbb162383a2d626ded6abccda7b4255dedb735be /src/util.rs | |
parent | c4f8c289147f26fa424692c30d656322c0a2e1e3 (diff) |
Make error printing show the whole chain of errors
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/util.rs')
-rw-r--r-- | src/util.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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) +} + |