Repository navigation
fix: keep the modules cache when the downloaded JSON is malformed - #708
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
_download_modules_json opened the cache with mode w before decoding the response, so an HTTP 200 with a malformed body truncated the cache and the CLI could not start. Decode first and write the replacement to a temporary file that replaces the cache only once complete. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Fixes #707
_download_modules_json()opened the modules cache with modewbefore evaluatingres.json(). If the CDN answers HTTP 200 with a malformed body, opening the file already truncates the usable cache and then the decoding raises. At startup that exception is swallowed, the fallback loads the now-empty cache, and the CLI fails to start instead of keeping the previous modules data.Fix: decode the response first, write the JSON to a temporary file next to the cache, and replace the cache only after that write succeeds. A malformed response or a failed write now leaves the existing cache as it was, and the temporary file is removed in every case.
Tests:
tests/models/test_download_modules_json.pycovers a malformed 200 response with a pre-existing cache (the cache content must be unchanged and no temporary file left) and a valid response replacing the cache. The first test fails without the change (the cache is empty afterwards) and passes with it;tests/modelsandtests/components/util/test_update_manager.pypass (141 tests).This change was prepared with the help of an AI assistant (Claude), and the submitter is responsible for it.