feat: enhance miette error diagnostics with source highlighting and URLs#183
feat: enhance miette error diagnostics with source highlighting and URLs#183
Conversation
Improves error handling across the codebase with better miette features: - Add ConfigParseError with source code highlighting for TOML parse errors Shows the exact location in config files where parsing failed - Use proper #[source] error chaining instead of stringified details Preserves the full error chain for better debugging - Add #[related] MultipleErrors for collecting validation errors - Add documentation URLs to all error types pointing to pitchfork.jdx.dev - Add #[label] annotations for inline error context - Add FileError::SerializeError for TOML serialization failures - Update IPC errors to use io::Error sources directly Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances error diagnostics by integrating miette's advanced features for better error reporting and debugging. The changes replace string-based error details with proper error chaining, add source code highlighting for TOML parse errors, and include documentation URLs for all error types.
Changes:
- Added
ConfigParseErrorwith source code highlighting to show exact locations of TOML parse failures - Replaced stringified error details with proper
#[source]error chaining across file and IPC errors - Added
MultipleErrorstype with#[related]for collecting validation errors, and documentation URLs to all error types
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/error.rs | Core changes: adds ConfigParseError with source highlighting, MultipleErrors for error collection, URLs to all error types, and converts error details to proper source chaining |
| src/pitchfork_toml.rs | Updates to use new ConfigParseError with source highlighting and FileError::SerializeError with proper error sources |
| src/state_file.rs | Updates to use FileError::SerializeError with proper error source instead of stringified details |
| src/ipc/client.rs | Converts IPC errors to use io::Error sources directly instead of stringified details |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| impl ConfigParseError { | ||
| /// Create a new ConfigParseError from a toml parse error | ||
| pub fn from_toml_error(path: &std::path::Path, contents: String, err: toml::de::Error) -> Self { | ||
| let message = err.message().to_string(); |
There was a problem hiding this comment.
The err.message() call already returns a &str, so calling .to_string() on it creates an unnecessary allocation. Consider using err.message() directly when constructing the struct or store it as &str if possible. This would improve performance for error handling, which is often in hot paths.
| #[diagnostic(code(pitchfork::multiple_errors))] | ||
| #[allow(dead_code)] | ||
| pub struct MultipleErrors { | ||
| #[related] | ||
| pub errors: Vec<Box<dyn Diagnostic + Send + Sync + 'static>>, | ||
| } | ||
|
|
There was a problem hiding this comment.
The MultipleErrors struct and its implementation methods are marked with #[allow(dead_code)], suggesting they're not currently used. If this code is intended for future use, consider adding a TODO comment explaining when it will be utilized. If it's meant to be used now, the dead code warning indicates missing usage that should be added.
| #[diagnostic(code(pitchfork::multiple_errors))] | |
| #[allow(dead_code)] | |
| pub struct MultipleErrors { | |
| #[related] | |
| pub errors: Vec<Box<dyn Diagnostic + Send + Sync + 'static>>, | |
| } | |
| #[diagnostic(code(pitchfork::multiple_errors))] | |
| // TODO: Integrate MultipleErrors where we need to aggregate and report all validation | |
| // errors at once instead of failing on the first error (e.g. bulk config validation). | |
| #[allow(dead_code)] | |
| pub struct MultipleErrors { | |
| #[related] | |
| pub errors: Vec<Box<dyn Diagnostic + Send + Sync + 'static>>, | |
| } | |
| // TODO: These helpers will be used once MultipleErrors is wired into the higher-level | |
| // validation/processing flow that aggregates individual diagnostics. |
## 🤖 New release * `pitchfork-cli`: 1.1.0 -> 1.2.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [1.2.0](v1.1.0...v1.2.0) - 2026-01-19 ### Added - enhance miette error diagnostics with source highlighting and URLs ([#183](#183)) - add structured IPC error types with miette diagnostics ([#181](#181)) - add structured config error types with file path context ([#182](#182)) - add config editor to TUI for creating and editing daemons ([#171](#171)) - add custom diagnostic error types with miette ([#180](#180)) ### Other - improve miette error handling adoption ([#177](#177)) - modularize supervisor.rs into focused submodules ([#175](#175)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Release 1.2.0** > > - Bump version to `1.2.0` in `Cargo.toml`, `Cargo.lock`, `docs/cli/commands.json`, `docs/cli/index.md`, and `pitchfork.usage.kdl` > - Regenerate CLI docs/usage specs to reflect the new version > - Update `CHANGELOG.md` with highlights: enhanced `miette` diagnostics (source highlighting, URLs), structured IPC/config error types, custom diagnostic errors, TUI config editor; plus adoption improvements and supervisor modularization > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 32b3259. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Summary
ConfigParseErrorwith source code highlighting for TOML parse errors - shows the exact location in config files where parsing failed#[source]error chaining instead of stringified details - preserves the full error chain for better debugging#[related]MultipleErrorsfor collecting validation errors#[label]annotations for inline error contextFileError::SerializeErrorfor TOML serialization failuresio::Errorsources directlyExample Error Output
With these changes, a TOML parse error now shows the exact location:
Test plan
🤖 Generated with Claude Code
Note
Improves error reporting and diagnostics across the codebase with richer miette integration.
ConfigParseErrorwithNamedSource/SourceSpan,#[label], and help text for TOML parse failures#[source]chaining inFileError/IpcError; adds URLs to diagnosticsFileError::SerializeErrorfor TOML serialization failurespitchfork_tomlread/write to use fs locks with context,std::fs::read_to_string,ConfigParseErroron parse, andSerializeErroron serializeio::Errorsources and useInvalidMessage { reason }MultipleErrorswith#[related]and new testsWritten by Cursor Bugbot for commit be09932. This will update automatically on new commits. Configure here.