feat: use anyhow for more structured error messages and better error reporting flexibility

This significantly changes the structure of potential output of
top-level errors.  Before, errors that have a `source` were printed on a
single line, with the `source` omitted. Now, an error with a `source`
will be printed like:

```
Error: <`Display` impl of error>

Caused by:
    <`Display` impl of `source` error>
```

If there are multiple `source` errors in a chain, then it will be of the
form:

```
Error: <`Display` impl of error>

Caused by:
    0: <`Display` impl of first `source` error>
    1: <`Display` impl of `source` of `source` error>
    # etc.
```

Now, in practice this never happened before, since the only error
type that ever could return from `<binary>::run` was `std::io::Error`,
which has no `source`. However, `source`s can start being added if, say,
future work involved using `anyhow::Context::context` or custom errors
that implement `std::Error::source` are added to the codebase. I believe
this is a good choice going forward, but I definitely want to foster
discussion and acceptance for it in the open first!
This commit is contained in:
Erich Gubler authored and David Peter committed 2020-06-17 18:05:42 +02:00
1 parent a7892881f3
commit 2bdf5d768f
4 files changed
+14 -4

No files matched your search

+1
View File
@@ -12,6 +12,7 @@ edition = "2018"
[dependencies]
ansi_term = "0.12"
anyhow = "1.0.31"
atty = "0.2"
libc = "0.2"