feat: add structured config error types with file path context#182
Conversation
Introduce ConfigError enum for better error reporting in config operations: - ParseError: includes file path and TOML parse error details - ReadError: includes file path and I/O error details - WriteError: includes file path and serialization/I/O error details - NoPath: when attempting to write without a path Updates pitchfork_toml.rs and state_file.rs to use these structured errors instead of generic into_diagnostic() calls. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces structured error handling for configuration file operations by adding a ConfigError enum with file path context. The changes improve error messages by providing specific error types and including file paths in error output.
Changes:
- Added
ConfigErrorenum with four variants:ParseError,ReadError,WriteError, andNoPath - Replaced generic error handling with specific
ConfigErrortypes in config file read/write operations - Added unit tests for config error display formatting
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/error.rs | Defines the new ConfigError enum with structured error variants and adds corresponding unit tests |
| src/pitchfork_toml.rs | Updates config file read/parse/write operations to use ConfigError with file path context |
| src/state_file.rs | Updates state file write operations to use ConfigError with file path context |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/pitchfork_toml.rs
Outdated
| path: path.clone(), | ||
| details: Some(format!("serialization failed: {}", e)), | ||
| })?; | ||
| xx::file::write(path, &raw).map_err(|e| ConfigError::WriteError { |
There was a problem hiding this comment.
The raw string is passed as &raw in line 76, but the same variable is passed without the reference operator in line 66 of state_file.rs. For consistency, use the same pattern in both locations.
| xx::file::write(path, &raw).map_err(|e| ConfigError::WriteError { | |
| xx::file::write(path, raw).map_err(|e| ConfigError::WriteError { |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Address PR feedback: - Rename ConfigError to FileError since it's used for both config and state files, making error messages accurate for all file types - Update error messages from "config file" to "file" so state file errors don't misleadingly reference config files - Update error codes from pitchfork::config::* to pitchfork::file::* - Remove unnecessary & from raw variable in xx::file::write calls for consistency between pitchfork_toml.rs and state_file.rs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## 🤖 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
ConfigErrorenum with structured error variants for config file operationspitchfork_toml.rsto useConfigErrorwith file pathsstate_file.rsto useConfigErrorfor write operationsError Types Added
ParseErrorReadErrorWriteErrorNoPathExample Output
Test plan
🤖 Generated with Claude Code
Note
Introduces structured file I/O diagnostics and applies them to config/state file operations.
FileErrorwithParseError/ReadError/WriteError/NoPathvariants including file path and optional details inerror.rs, plus unit testspitchfork_toml.rsto map read/parse/write failures toFileErrorand returnNoPathinstead of a generic bailstate_file.rsto useFileErrorfor serialization/write errors (read path still logs and defaults)Written by Cursor Bugbot for commit dd4fd5b. This will update automatically on new commits. Configure here.