feat: add custom diagnostic error types with miette#180
Conversation
Introduce structured error types for better error reporting: - DaemonIdError: validation errors with error codes and help text - DependencyError: resolution errors with fuzzy matching suggestions Benefits: - Error codes (pitchfork::daemon::*, pitchfork::deps::*) - Contextual help messages - "Did you mean?" suggestions for daemon names - Cleaner error handling in daemon.rs and deps.rs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces structured diagnostic error types using the miette library to provide better error messages with error codes, help text, and fuzzy matching suggestions for daemon and dependency-related errors.
Changes:
- Added
error.rsmodule withDaemonIdErrorandDependencyErrorenums - Migrated
daemon.rsanddeps.rsto use structured error types instead of generic error messages - Added
thiserrordependency for error derive macros
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main.rs | Added error module declaration |
| src/lib.rs | Exposed error module publicly |
| src/error.rs | Implemented structured error types with diagnostic codes and help text |
| src/deps.rs | Migrated to use DependencyError with fuzzy matching suggestions |
| src/daemon.rs | Migrated to use DaemonIdError for validation errors |
| Cargo.toml | Added thiserror v2 dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // False positive: fields are used in #[error] format strings via thiserror derive | ||
| #![allow(unused_assignments)] |
There was a problem hiding this comment.
The comment mentions 'unused_assignments' is a false positive for fields used in #[error] format strings, but the actual lint being suppressed is for unused fields (dead_code), not assignments. The unused_assignments lint applies to variable assignments, not struct fields. Consider using #![allow(dead_code)] instead if that's the intended suppression.
| // False positive: fields are used in #[error] format strings via thiserror derive | |
| #![allow(unused_assignments)] | |
| // False positive: fields are used in #[error] format strings via thiserror derive (dead_code) | |
| #![allow(dead_code)] |
| use fuzzy_matcher::FuzzyMatcher; | ||
| use fuzzy_matcher::skim::SkimMatcherV2; |
There was a problem hiding this comment.
The fuzzy_matcher dependency is used in this function but not declared in Cargo.toml. This will cause a compilation error. Add the fuzzy-matcher crate to the dependencies.
## 🤖 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
DaemonIdErrorenum with error codes and help text for daemon ID validationDependencyErrorenum for dependency resolution errors with fuzzy matching suggestionsdaemon.rsanddeps.rsto use the new structured error typesBenefits
pitchfork::daemon::*,pitchfork::deps::*) for better searchabilityExample Output
Test plan
src/error.rscargo clippy🤖 Generated with Claude Code
Note
Introduces a new
errormodule with structuredmiettediagnostics and updates callers.src/error.rsdefiningDaemonIdErrorandDependencyError(error codes, help text, fuzzy “did you mean?” suggestions)daemon.rs::validate_daemon_idanddeps.rs::resolve_dependenciesto use these errors; adjust test assertions for new messageslib.rs/main.rs; addthiserrorandfuzzy-matcherdependenciesWritten by Cursor Bugbot for commit 5af3bca. This will update automatically on new commits. Configure here.