Skip to content

feat: enhance miette error diagnostics with source highlighting and URLs#183

Merged
jdx merged 1 commit intomainfrom
feat/miette-improvements
Jan 19, 2026
Merged

feat: enhance miette error diagnostics with source highlighting and URLs#183
jdx merged 1 commit intomainfrom
feat/miette-improvements

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • 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

Example Error Output

With these changes, a TOML parse error now shows the exact location:

  × failed to parse configuration
   ╭─[pitchfork.toml:5:1]
 4 │ [daemons.api]
 5 │ run = 
   ·       ╰── expected string
   ╰────
  help: check TOML syntax at https://toml.io

Test plan

  • All existing tests pass (91/91)
  • Clippy passes with no warnings
  • Formatting verified

🤖 Generated with Claude Code


Note

Improves error reporting and diagnostics across the codebase with richer miette integration.

  • Introduces ConfigParseError with NamedSource/SourceSpan, #[label], and help text for TOML parse failures
  • Converts string "details" to proper #[source] chaining in FileError/IpcError; adds URLs to diagnostics
  • Adds FileError::SerializeError for TOML serialization failures
  • Updates pitchfork_toml read/write to use fs locks with context, std::fs::read_to_string, ConfigParseError on parse, and SerializeError on serialize
  • Updates IPC client to propagate io::Error sources and use InvalidMessage { reason }
  • Adds MultipleErrors with #[related] and new tests

Written by Cursor Bugbot for commit be09932. This will update automatically on new commits. Configure here.

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>
Copilot AI review requested due to automatic review settings January 19, 2026 22:47
Copy link
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

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 ConfigParseError with 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 MultipleErrors type 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();
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +249 to +255
#[diagnostic(code(pitchfork::multiple_errors))]
#[allow(dead_code)]
pub struct MultipleErrors {
#[related]
pub errors: Vec<Box<dyn Diagnostic + Send + Sync + 'static>>,
}

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
#[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.

Copilot uses AI. Check for mistakes.
@jdx jdx merged commit 7d7d673 into main Jan 19, 2026
4 checks passed
@jdx jdx deleted the feat/miette-improvements branch January 19, 2026 23:04
@jdx jdx mentioned this pull request Jan 19, 2026
jdx added a commit that referenced this pull request Jan 20, 2026
## 🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants