feat: improve error printing#517
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates cot-core::Error’s Debug formatting so that {:?} produces a human-friendly error message plus its source chain (similar to anyhow), while {:#?} retains the original structured debug output. This improves the default panic output from Result::unwrap() / expect() in cot::main.
Changes:
- Implement non-alternate
Debugformatting to print the error viaDisplayplus a “caused by” source chain. - Preserve the prior
Debugoutput behind alternate formatting ({:#?}).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Branch | improve-errors |
| Testbed | github-ubuntu-latest |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result microseconds (µs) (Result Δ%) | Upper Boundary microseconds (µs) (Limit %) |
|---|---|---|---|
| empty_router/empty_router | 📈 view plot 🚷 view threshold | 6,774.80 µs(+11.19%)Baseline: 6,093.20 µs | 7,677.76 µs (88.24%) |
| json_api/json_api | 📈 view plot 🚷 view threshold | 1,054.60 µs(-1.84%)Baseline: 1,074.37 µs | 1,323.65 µs (79.67%) |
| nested_routers/nested_routers | 📈 view plot 🚷 view threshold | 1,016.20 µs(+2.40%)Baseline: 992.35 µs | 1,204.08 µs (84.40%) |
| single_root_route/single_root_route | 📈 view plot 🚷 view threshold | 959.17 µs(+0.46%)Baseline: 954.82 µs | 1,167.50 µs (82.16%) |
| single_root_route_burst/single_root_route_burst | 📈 view plot 🚷 view threshold | 18,737.00 µs(+5.71%)Baseline: 17,724.56 µs | 21,190.21 µs (88.42%) |
seqre
reviewed
Mar 22, 2026
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
seqre
requested changes
Mar 29, 2026
Member
seqre
left a comment
There was a problem hiding this comment.
Please make cargo insta test for this functionality
When using `Result::expect()`, (e.g. in the default `cot::main`) errors are printed using `Debug` printer. This causes very ugly errors to be produced. Instead, when the alternate mode is not being used, just format the error nicely, along with the error source chain. This roughly duplicates the `anyhow::Error` error printing logic: https://docs.rs/anyhow/latest/anyhow/struct.Error.html#method.chain
Comment on lines
+180
to
+183
| let error = self.inner(); | ||
| Display::fmt(error, f)?; | ||
|
|
||
| if let Some(source) = error.source() { |
seqre
reviewed
May 21, 2026
seqre
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using
Result::expect(), (e.g. in the defaultcot::main) errors are printed usingDebugprinter. This causes very ugly errors to be produced. Instead, when the alternate mode is not being used, just format the error nicely, along with the error source chain.This roughly duplicates the
anyhow::Errorerror printing logic: https://docs.rs/anyhow/latest/anyhow/struct.Error.html#method.chainThe change turns this:

into this:
