fix: recover gracefully from corrupt/empty mapImage.png on startup#518
Draft
dmccoystephenson wants to merge 3 commits into
Draft
fix: recover gracefully from corrupt/empty mapImage.png on startup#518dmccoystephenson wants to merge 3 commits into
dmccoystephenson wants to merge 3 commits into
Conversation
In the web/WASM environment (OPFS), a partially-written or zero-byte mapImage.png passes os.path.exists() but then causes PIL to throw UnidentifiedImageError. Catch all image-open exceptions in getExistingMapImage() and fall back to createNewMapImage() so the game loads instead of crashing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without explicit cache headers, browsers serve stale game.zip after a redeploy, masking fixes until the user hard-refreshes. Force revalidation for all .zip and .js paths so a new container image is always picked up. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
build_zip.py now writes a SHA-256 of game.zip to web/game_version.txt. game-worker.js fetches that file with cache:'no-store' and appends the hash as ?v=<hash> to the zip URL. A new deploy changes the hash, changes the URL, and forces every browser to download the new bundle — no hard refresh or cache clearing needed. serve.py applies no-store to game_version.txt and no-cache to .zip/.js. Both generated files (game.zip, game_version.txt) added to .gitignore. Co-Authored-By: Claude Sonnet 4.6 <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.
Summary
mapImage.pngpassesos.path.exists()but causes PIL to throwUnidentifiedImageErrorat startup, crashing the game before the first frame renders.getExistingMapImage()now catches any image-open exception and falls back tocreateNewMapImage(), logging a warning so the bad file is detectable in logs.Root cause
mapImageExists()only checks file presence, not validity. OPFS/IndexedDB can leave a zero-byte or partially-flushed file behind after an interrupted save, which PIL cannot parse.Test plan
python3 -m pytest tests/ -q— all tests passpython3 -m black --check src tests— no formatting violationsmapImage.pngin the save dir — game starts instead of throwingUnidentifiedImageError🤖 Generated with Claude Code