Skip to content

feat: improve error printing#517

Merged
seqre merged 6 commits into
masterfrom
improve-errors
May 21, 2026
Merged

feat: improve error printing#517
seqre merged 6 commits into
masterfrom
improve-errors

Conversation

@m4tx
Copy link
Copy Markdown
Member

@m4tx m4tx commented Mar 22, 2026

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

The change turns this:
before

into this:
after

Copilot AI review requested due to automatic review settings March 22, 2026 15:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Debug formatting to print the error via Display plus a “caused by” source chain.
  • Preserve the prior Debug output behind alternate formatting ({:#?}).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cot-core/src/error/error_impl.rs Outdated
Comment thread cot-core/src/error/error_impl.rs Outdated
Comment thread cot-core/src/error/error_impl.rs
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 22, 2026

🐰 Bencher Report

Branchimprove-errors
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark 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%)
🐰 View full continuous benchmarking report in Bencher

Comment thread cot-core/src/error/error_impl.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 93.33333% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot-core/src/error/error_impl.rs 93.33% 0 Missing and 5 partials ⚠️
Flag Coverage Δ
rust 90.33% <93.33%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot-core/src/error/error_impl.rs 96.29% <93.33%> (-0.19%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@seqre seqre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@m4tx m4tx force-pushed the improve-errors branch from add338d to 0eaa5ff Compare May 18, 2026 16:53
@github-actions github-actions Bot added C-core A-deps Area: Dependencies labels May 18, 2026
@m4tx m4tx force-pushed the improve-errors branch from f46a88f to 4fdec56 Compare May 18, 2026 19:33
@m4tx m4tx requested review from a team, Copilot and seqre May 18, 2026 19:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

Comment on lines +180 to +183
let error = self.inner();
Display::fmt(error, f)?;

if let Some(source) = error.source() {
Comment thread cot-core/src/error/error_impl.rs
Comment thread cot-core/src/error/error_impl.rs
Comment thread cot-core/src/error/error_impl.rs
Comment thread cot-core/src/error/error_impl.rs
@m4tx m4tx requested a review from seqre May 21, 2026 09:56
@seqre seqre enabled auto-merge (squash) May 21, 2026 10:51
@seqre seqre merged commit 448b7b0 into master May 21, 2026
40 checks passed
@seqre seqre deleted the improve-errors branch May 21, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-deps Area: Dependencies C-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants