Skip to content

feat: add structured config error types with file path context#182

Merged
jdx merged 2 commits intomainfrom
feat/miette-config-errors
Jan 19, 2026
Merged

feat: add structured config error types with file path context#182
jdx merged 2 commits intomainfrom
feat/miette-config-errors

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • Add ConfigError enum with structured error variants for config file operations
  • Update pitchfork_toml.rs to use ConfigError with file paths
  • Update state_file.rs to use ConfigError for write operations

Error Types Added

Error When Context
ParseError TOML parsing fails File path + parse error details
ReadError File read fails File path + I/O error details
WriteError Serialization or write fails File path + error details
NoPath Write without path Suggests creating pitchfork.toml

Example Output

Error: pitchfork::config::parse_error

  × failed to parse config file: /home/user/project/pitchfork.toml

  help: expected newline, found an identifier at line 3 column 5

Test plan

  • All existing tests pass
  • New unit tests for config error types
  • Lints pass

🤖 Generated with Claude Code


Note

Introduces structured file I/O diagnostics and applies them to config/state file operations.

  • Adds FileError with ParseError/ReadError/WriteError/NoPath variants including file path and optional details in error.rs, plus unit tests
  • Updates pitchfork_toml.rs to map read/parse/write failures to FileError and return NoPath instead of a generic bail
  • Updates state_file.rs to use FileError for 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.

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>
Copilot AI review requested due to automatic review settings January 19, 2026 19:50
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 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 ConfigError enum with four variants: ParseError, ReadError, WriteError, and NoPath
  • Replaced generic error handling with specific ConfigError types 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.

path: path.clone(),
details: Some(format!("serialization failed: {}", e)),
})?;
xx::file::write(path, &raw).map_err(|e| ConfigError::WriteError {
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 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.

Suggested change
xx::file::write(path, &raw).map_err(|e| ConfigError::WriteError {
xx::file::write(path, raw).map_err(|e| ConfigError::WriteError {

Copilot uses AI. Check for mistakes.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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>
@jdx jdx merged commit 098fa47 into main Jan 19, 2026
4 checks passed
@jdx jdx deleted the feat/miette-config-errors branch January 19, 2026 22:20
@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