Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/src/antipattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,5 @@ mod http {
// Notice "failed to send request" appears twice with no new information.
//
// Error: fatal error occurred in application, at examples/src/antipattern.rs:35:16
// |
// |-> failed to send request, at examples/src/antipattern.rs:59:34
// |
// |-> failed to send request to server: 127.0.0.1, at examples/src/antipattern.rs:75:9
// |-- failed to send request, at examples/src/antipattern.rs:59:34
// `-- failed to send request to server: 127.0.0.1, at examples/src/antipattern.rs:75:9
6 changes: 2 additions & 4 deletions examples/src/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,5 @@ mod http {
// Output when running `cargo run --example basic`:
//
// Error: fatal error occurred in application, at examples/src/basic.rs:34:16
// |
// |-> failed to run app, at examples/src/basic.rs:49:14
// |
// |-> failed to send request to server: https://example.com, at examples/src/basic.rs:62:9
// |-- failed to run app, at examples/src/basic.rs:49:14
// `-- failed to send request to server: https://example.com, at examples/src/basic.rs:62:9
6 changes: 2 additions & 4 deletions examples/src/downcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,5 @@ mod http {
//
// HTTP error with status code: 503
// Error: fatal error occurred in application, at examples/src/downcast.rs:54:24
// |
// |-> failed to run app, at examples/src/downcast.rs:82:35
// |
// |-> HTTP 503: service unavailable, at examples/src/downcast.rs:95:9
// |-- failed to run app, at examples/src/downcast.rs:82:35
// `-- HTTP 503: service unavailable, at examples/src/downcast.rs:95:9
9 changes: 3 additions & 6 deletions examples/src/from-anyhow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ mod legacy {
// Output when running `cargo run -p examples --example from-anyhow`:
//
// Error: fatal error occurred in application, at examples/src/from-anyhow.rs:27:16
// |
// |-> failed to run app, at examples/src/from-anyhow.rs:42:14
// |
// |-> PORT must be a number; got "not-a-number", at exn-anyhow/src/lib.rs:51:19
// |
// |-> invalid digit found in string, at exn-anyhow/src/lib.rs:48:19
// |-- failed to run app, at examples/src/from-anyhow.rs:42:14
// |-- PORT must be a number; got "not-a-number", at exn-anyhow/src/lib.rs:51:19
// `-- invalid digit found in string, at exn-anyhow/src/lib.rs:48:19
6 changes: 2 additions & 4 deletions examples/src/into-std-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,5 @@ mod config {
// Output when running `cargo run -p examples --example into-std-error`:
//
// Error: failed to start app, at examples/src/into-std-error.rs:36:40
// |
// |-> PORT must be a number; got "not-a-number", at examples/src/into-std-error.rs:55:14
// |
// |-> invalid digit found in string, at examples/src/into-std-error.rs:55:14
// |-- PORT must be a number; got "not-a-number", at examples/src/into-std-error.rs:55:14
// `-- invalid digit found in string, at examples/src/into-std-error.rs:55:14
12 changes: 4 additions & 8 deletions examples/src/library-boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,11 @@ mod library {
//
// Action: Retried too many times, aborting
// Error: RateLimited: rate limited by upstream, at examples/src/library-boundary.rs:149:13
// |
// |-> failed to fetch profile for user 429, at examples/src/library-boundary.rs:170:55
// |
// |-> HTTP 429: too many requests, at examples/src/library-boundary.rs:218:24
// |-- failed to fetch profile for user 429, at examples/src/library-boundary.rs:170:55
// `-- HTTP 429: too many requests, at examples/src/library-boundary.rs:218:24
//
// Start demo for user: 404
// Action: Return 404
// Error: NotFound: user 404 not found, at examples/src/library-boundary.rs:149:13
// |
// |-> failed to fetch profile for user 404, at examples/src/library-boundary.rs:169:47
// |
// |-> no row for user_id 404, at examples/src/library-boundary.rs:189:24
// |-- failed to fetch profile for user 404, at examples/src/library-boundary.rs:169:47
// `-- no row for user_id 404, at examples/src/library-boundary.rs:189:24
13 changes: 9 additions & 4 deletions exn/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ fn write_exn(f: &mut fmt::Formatter<'_>, frame: &Frame, level: usize, prefix: &s
let children_len = children.len();

for (i, child) in children.iter().enumerate() {
write!(f, "\n{}|", prefix)?;
write!(f, "\n{}|-> ", prefix)?;

let child_child_len = child.children().len();
if level == 0 && children_len == 1 && child_child_len == 1 {
let is_linear = level == 0 && children_len == 1 && child_child_len == 1;

if i != children_len - 1 || is_linear {
write!(f, "\n{}|-- ", prefix)?;
} else {
write!(f, "\n{}`-- ", prefix)?;
}
Comment thread
andylokandy marked this conversation as resolved.

if is_linear {
write_exn(f, child, 0, prefix)?;
} else if i < children_len - 1 {
write_exn(f, child, level + 1, &format!("{}| ", prefix))?;
Expand Down
3 changes: 1 addition & 2 deletions exn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
//!
//! ```text
//! fatal error: math no longer works, at exn/src/lib.rs:44:16
//! |
//! |-> logic error: 0 == 1, at exn/src/lib.rs:40:5
//! `-- logic error: 0 == 1, at exn/src/lib.rs:40:5
//! ```

#![cfg_attr(docsrs, feature(doc_cfg))]
Expand Down
10 changes: 10 additions & 0 deletions exn/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use exn::ErrorExt;
use exn::Exn;
use exn::OptionExt;
use exn::ResultExt;
Expand All @@ -27,6 +28,15 @@ fn linear_error() {
insta::assert_debug_snapshot!(e);
}

#[test]
fn tree_then_linear_error() {
let t1 = common::new_linear_error().raise(Error("T1"));
let t2 = Error("T2").raise();
let e = Exn::raise_all(Error("topmost"), [t1, t2]);
assert_eq!(e.to_string(), "topmost");
insta::assert_debug_snapshot!(e);
}

#[test]
fn tree_error() {
let e = common::new_tree_error().raise(Error("topmost"));
Expand Down
2 changes: 1 addition & 1 deletion exn/tests/snapshots/main__bail.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: exn/tests/main.rs
expression: result.unwrap_err()
---
An error, at exn/tests/main.rs:71:9
An error, at exn/tests/main.rs:81:9
2 changes: 1 addition & 1 deletion exn/tests/snapshots/main__ensure_fail.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: exn/tests/main.rs
expression: result.unwrap_err()
---
An error, at exn/tests/main.rs:91:9
An error, at exn/tests/main.rs:101:9
2 changes: 1 addition & 1 deletion exn/tests/snapshots/main__from_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: exn/tests/main.rs
expression: result.unwrap_err()
---
An error, at exn/tests/main.rs:60:9
An error, at exn/tests/main.rs:70:9
17 changes: 6 additions & 11 deletions exn/tests/snapshots/main__linear_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@
source: exn/tests/main.rs
expression: e
---
topmost, at exn/tests/main.rs:25:40
|
|-> E5, at exn/tests/common.rs:44:8
|
|-> E4, at exn/tests/common.rs:43:17
|
|-> E3, at exn/tests/common.rs:42:17
|
|-> E2, at exn/tests/common.rs:41:17
|
|-> E1, at exn/tests/common.rs:40:26
topmost, at exn/tests/main.rs:26:40
|-- E5, at exn/tests/common.rs:44:8
|-- E4, at exn/tests/common.rs:43:17
|-- E3, at exn/tests/common.rs:42:17
|-- E2, at exn/tests/common.rs:41:17
`-- E1, at exn/tests/common.rs:40:26
5 changes: 2 additions & 3 deletions exn/tests/snapshots/main__new_with_source.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
source: exn/tests/main.rs
expression: e
---
top, at exn/tests/main.rs:39:13
|
|-> source, at exn/tests/main.rs:39:13
top, at exn/tests/main.rs:49:13
`-- source, at exn/tests/main.rs:49:13
2 changes: 1 addition & 1 deletion exn/tests/snapshots/main__option_ext.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: exn/tests/main.rs
expression: result.unwrap_err()
---
An error, at exn/tests/main.rs:53:25
An error, at exn/tests/main.rs:63:25
5 changes: 2 additions & 3 deletions exn/tests/snapshots/main__result_ext.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
source: exn/tests/main.rs
expression: result.unwrap_err()
---
Another error, at exn/tests/main.rs:46:25
|
|-> An error, at exn/tests/main.rs:46:25
Another error, at exn/tests/main.rs:56:25
`-- An error, at exn/tests/main.rs:56:25
38 changes: 13 additions & 25 deletions exn/tests/snapshots/main__tree_error.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,16 @@
source: exn/tests/main.rs
expression: e
---
topmost, at exn/tests/main.rs:32:38
|
|-> E6, at exn/tests/common.rs:36:5
|
|-> E5, at exn/tests/common.rs:28:14
| |
| |-> E3, at exn/tests/common.rs:20:17
| | |
| | |-> E1, at exn/tests/common.rs:19:26
| |
| |-> E10, at exn/tests/common.rs:23:18
| | |
| | |-> E9, at exn/tests/common.rs:22:26
| |
| |-> E12, at exn/tests/common.rs:26:19
| |
| |-> E11, at exn/tests/common.rs:25:28
|
|-> E4, at exn/tests/common.rs:31:17
| |
| |-> E2, at exn/tests/common.rs:30:26
|
|-> E8, at exn/tests/common.rs:34:17
|
|-> E7, at exn/tests/common.rs:33:26
topmost, at exn/tests/main.rs:42:38
`-- E6, at exn/tests/common.rs:36:5
|-- E5, at exn/tests/common.rs:28:14
| |-- E3, at exn/tests/common.rs:20:17
| | `-- E1, at exn/tests/common.rs:19:26
| |-- E10, at exn/tests/common.rs:23:18
| | `-- E9, at exn/tests/common.rs:22:26
| `-- E12, at exn/tests/common.rs:26:19
| `-- E11, at exn/tests/common.rs:25:28
|-- E4, at exn/tests/common.rs:31:17
| `-- E2, at exn/tests/common.rs:30:26
`-- E8, at exn/tests/common.rs:34:17
`-- E7, at exn/tests/common.rs:33:26
12 changes: 12 additions & 0 deletions exn/tests/snapshots/main__tree_then_linear_error.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: exn/tests/main.rs
expression: e
---
topmost, at exn/tests/main.rs:35:13
|-- T1, at exn/tests/main.rs:33:41
| `-- E5, at exn/tests/common.rs:44:8
| `-- E4, at exn/tests/common.rs:43:17
| `-- E3, at exn/tests/common.rs:42:17
| `-- E2, at exn/tests/common.rs:41:17
| `-- E1, at exn/tests/common.rs:40:26
`-- T2, at exn/tests/main.rs:34:26