fix(collector): handle malformed previous overview and allow self-healing (#1) - #3
Open
goanscryca wants to merge 1 commit into
Open
goanscryca wants to merge 1 commit into
goanscryca wants to merge 1 commit into
Conversation
…elf-healing When reading previous state from -output, an invalid or truncated JSON document (e.g. from an interrupted write or trailing bytes) caused jq to fail or emit multiple values, breaking --argjson previous and aborting subsequent collector runs indefinitely. Now gitwork validates that the previous file is a single JSON object. If it is invalid or empty, gitwork logs a warning to stderr, falls back to null (empty state) and replaces the corrupt file with a valid overview on the current run. Resolves ariadev#1
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.
Resolves #1
Summary
When
bin/gitworkreads its previous overview file (-output, e.g.overview.json) to carry forward state, an invalid JSON file (such as one corrupted by an interrupted write or trailing bytes) causedjq -c .to fail or stream multiple tokens. As a result, passing it tojq --argjson previous "$previous"failed withinvalid JSON text passed to --argjson, permanently crashing every subsequent collector run.Changes
jq -c -s 'if length == 1 and (.[0] | type == "object") then .[0] else empty end'. If the document is not a single valid JSON object, it is treated as missing (null).gitworkemits a warning tostderrand proceeds with an empty previous state, replacing the broken file with a fresh, valid overview.tests/collector-test.shasserting that a corrupted previous file (overview.jsonwith trailing syntax errors) emits a warning, recovers cleanly, writes valid JSON, and preserves the schema version.Verification
All test suites pass:
tests/calendar-test.sh: 38 passed, 0 failedtests/carry-forward-test.sh: 25 passed, 0 failedtests/collector-test.sh: 37 passed, 0 failedtests/hosts-test.sh: 32 passed, 0 failedtests/items-test.sh: 52 passed, 0 failed