fix(tracker-client): improve error message when JSON config is not well-formatted (#1042)#1764
Merged
josecelano merged 9 commits intoMay 12, 2026
Conversation
…d testing requirements
…rs (torrust#1042) - Added `error.rs` with `ConfigSource` and `AppError` types that decouple delivery mechanism from error presentation - Replaced generic `.context("invalid config format")` with source-aware `AppError::InvalidConfig` - Binary no longer panics on config errors; prints JSON envelope to stderr and exits with code 2 (config) or 1 (runtime) - Follows Tracker CLI I/O Contract: `{"error":{"kind":"...","source":"...","message":"..."}}` - Added 12 unit tests and 9 integration tests; all 44 tests pass
Reflect that implementation is now in-progress following rebase completion: - Update status: planned → in-progress - Correct branch name to match actual branch - Update last-updated timestamp to reflect rebase completion - Replace skill-link references with actual I/O contract ADR and documentation
Document 6 manual test scenarios covering: - Valid configuration with tracker demo URLs - JSON parse error from environment variable (trailing comma) - JSON parse error from environment variable (missing bracket) - JSON parse error from configuration file (shows file path in source) - Missing configuration (no config provided) - Configuration validation error (invalid URL) All tests pass and verify exit codes (0 for success, 2 for config errors) and error output format. Error envelopes are compliant with Tracker CLI I/O Contract schema and are correctly written to stderr.
There was a problem hiding this comment.
Pull request overview
This PR updates the tracker_checker CLI to surface configuration/JSON parsing failures as contract-compliant structured JSON errors (stderr) with deterministic exit codes, instead of panicking with a generic message.
Changes:
- Introduces
AppError/ConfigSourcefor checker-specific error classification and formatting. - Refactors config loading/parsing to return structured config errors and maps runtime failures to exit code
1. - Adds unit + integration tests for malformed/missing configuration and exit code semantics.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
docs/issues/open/1042-tracker-checker-http-improve-error-message-json-config.md |
Updates the issue spec to reference the CLI I/O contract and acceptance evidence. |
console/tracker-client/tests/tracker_checker.rs |
Adds E2E tests asserting stderr JSON envelope + exit code 2 for config errors. |
console/tracker-client/src/console/clients/checker/mod.rs |
Exposes the new error module. |
console/tracker-client/src/console/clients/checker/error.rs |
Adds structured AppError + config source tracking and JSON error envelope generation. |
console/tracker-client/src/console/clients/checker/config.rs |
Adds unit tests ensuring parse/validation error details are preserved. |
console/tracker-client/src/console/clients/checker/app.rs |
Replaces anyhow config errors with AppError and propagates parse details. |
console/tracker-client/src/bin/tracker_checker.rs |
Replaces panic-on-error with JSON-to-stderr + exit code handling. |
console/tracker-client/Cargo.toml |
Adds tempfile dev-dependency for integration tests. |
Cargo.lock |
Locks tempfile dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1764 +/- ##
===========================================
- Coverage 79.44% 79.05% -0.40%
===========================================
Files 369 370 +1
Lines 27328 27682 +354
Branches 27328 27682 +354
===========================================
+ Hits 21710 21883 +173
- Misses 5337 5517 +180
- Partials 281 282 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
|
ACK 36ed8ef |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1042 — Tracker Checker (HTTP): Improve Error Message When JSON Config Is Not Well-Formatted
When the Tracker Checker received a malformed JSON configuration (e.g. a trailing comma), it
panicked with a generic
invalid config formatmessage. The detailed parse error was buried inthe "Caused by" chain, invisible without
RUST_BACKTRACE=1.Changes
console/tracker-client/src/console/clients/checker/error.rs(new):ConfigSourceenum(env var or file path) and
AppErrorenum (InvalidConfig/Runtime) with JSON serializationto the Tracker CLI I/O Contract schema.
console/tracker-client/src/console/clients/checker/app.rs: Refactoredsetup_configandload_config_from_fileto returnAppErrorinstead ofanyhow. Parse errors now propagatewith source context instead of a generic wrapper.
console/tracker-client/src/bin/tracker_checker.rs: Replaced.expect()panic withstructured error handling — JSON error written to stderr, exits with code 2 for config errors.
console/tracker-client/src/console/clients/checker/config.rs: Added 5 new unit tests forparse error propagation.
console/tracker-client/tests/tracker_checker.rs(new): 9 end-to-end integration testscovering env var and file config sources.
Error Output (before vs. after)
Before:
After:
Exit code:
2Testing
linter allexits 0)Issue Spec
docs/issues/open/1042-tracker-checker-http-improve-error-message-json-config.md