[PR #918] viewer: say the world file could not be read when the body read fails, not that the JSON is invalid (WORLD-JSON-READ-MISREPORTED) #955

Open
opened 2026-11-26 20:19:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/918
Author: @TuroYT
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/viewer-world-json-read-error


📝 Commits (1)

  • 23b7059 viewer: report body read failures separately from invalid JSON (WORLD-JSON-READ-MISREPORTED)

📊 Changes

2 files changed (+28 additions, -9 deletions)

View changed files

📝 tests/test_viewer_streaming.cjs (+19 -4)
📝 viewer/index.html (+9 -5)

📄 Description

Claimed in the coordination issue as: WORLD-JSON-READ-MISREPORTED (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135526454)

What was wrong

viewer/index.html, loadWorld() (line 119 before this change): world = await response.json(); ran inside the same try as the fetch. The catch chose its message from response, which is set once the fetch has returned. So when the status was 200 and the body read failed (for example a dropped connection), the viewer said world/world.json could not be read as valid JSON. The file may be valid, and the failure was the network.

Reproduction on main (a28927849), with a stubbed fetch and the function read from the file in memory:

200 + body read fails -> "world/world.json could not be read as valid JSON."
no response          -> "world/world.json could not be loaded."

What changed

  • loadWorld() reads the body with response.text() and parses it with JSON.parse as two separate steps. A stage variable records which step was running when the error was thrown.
  • The catch now returns:
    • ... could not be read. when the read failed,
    • ... could not be read as valid JSON. when the parse failed,
    • ... could not be loaded. when the fetch failed (unchanged),
    • ... download timed out. when the deadline fired (unchanged).
  • Test mocks that provided json: now provide text:. The test sandbox gets the host JSON, so parsed arrays compare as before.
  • New cases: a read that throws after a 200 response expects could not be read. and not valid JSON; a valid body still loads.

Overlap with open pull requests

  • #651 (VIEWER-CHUNK-IDLE-TIMEOUT) edits loadChunk in viewer/index.html and adds fixtures and tests after line 456 of the test file. This pull request does not touch those hunks. Its loadWorld hunk is at lines 110-130, and its test hunks are at lines 21-22, 68-95 and 110.
  • #93 changes one camera speed test in the test file. No overlap.
  • No other open pull request touches these two files for loadWorld.

Tested

node --test tests/test_viewer_streaming.cjs        # node v24.22.0
# tests 59, pass 59, fail 0
python3 -I tests/test_text_write_line_endings.py   # Ran 3 tests, OK
python3 -I scripts/check_no_game_data.py viewer/index.html tests/test_viewer_streaming.cjs   # exit 0
git diff --check                                   # no output

The new cases fail on the unfixed viewer/index.html (the main version, run with the new test file):

node --test --test-name-pattern="read failure|body read that fails|valid manifest body still loads|test mode, a missing" tests/test_viewer_streaming.cjs
# tests 3, pass 1, fail 2
# AssertionError: 'world/world.json could not be read as valid JSON.' does not match /could not be read\./

The valid-body case also fails on the unfixed code, because its mock provides only text() and the old code calls json().

Not tested: a real browser. The viewer was not served or opened, so no page load, console or network check was done. The change is inside loadWorld(), which runs once at startup. No GPU, no game files.

AI-assisted (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/918 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/viewer-world-json-read-error` --- ### 📝 Commits (1) - [`23b7059`](https://github.com/ubiquitarianism/leonida/commit/23b70597de2fa197a9f5b23e0c0f6026798cf7c9) viewer: report body read failures separately from invalid JSON (WORLD-JSON-READ-MISREPORTED) ### 📊 Changes **2 files changed** (+28 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_viewer_streaming.cjs` (+19 -4) 📝 `viewer/index.html` (+9 -5) </details> ### 📄 Description Claimed in the coordination issue as: WORLD-JSON-READ-MISREPORTED (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135526454) ## What was wrong `viewer/index.html`, `loadWorld()` (line 119 before this change): `world = await response.json();` ran inside the same try as the fetch. The catch chose its message from `response`, which is set once the fetch has returned. So when the status was 200 and the body read failed (for example a dropped connection), the viewer said `world/world.json could not be read as valid JSON.` The file may be valid, and the failure was the network. Reproduction on `main` (`a28927849`), with a stubbed fetch and the function read from the file in memory: ``` 200 + body read fails -> "world/world.json could not be read as valid JSON." no response -> "world/world.json could not be loaded." ``` ## What changed - `loadWorld()` reads the body with `response.text()` and parses it with `JSON.parse` as two separate steps. A `stage` variable records which step was running when the error was thrown. - The catch now returns: - `... could not be read.` when the read failed, - `... could not be read as valid JSON.` when the parse failed, - `... could not be loaded.` when the fetch failed (unchanged), - `... download timed out.` when the deadline fired (unchanged). - Test mocks that provided `json:` now provide `text:`. The test sandbox gets the host `JSON`, so parsed arrays compare as before. - New cases: a read that throws after a 200 response expects `could not be read.` and not `valid JSON`; a valid body still loads. ## Overlap with open pull requests - #651 (VIEWER-CHUNK-IDLE-TIMEOUT) edits `loadChunk` in `viewer/index.html` and adds fixtures and tests after line 456 of the test file. This pull request does not touch those hunks. Its `loadWorld` hunk is at lines 110-130, and its test hunks are at lines 21-22, 68-95 and 110. - #93 changes one camera speed test in the test file. No overlap. - No other open pull request touches these two files for `loadWorld`. ## Tested ``` node --test tests/test_viewer_streaming.cjs # node v24.22.0 # tests 59, pass 59, fail 0 python3 -I tests/test_text_write_line_endings.py # Ran 3 tests, OK python3 -I scripts/check_no_game_data.py viewer/index.html tests/test_viewer_streaming.cjs # exit 0 git diff --check # no output ``` The new cases fail on the unfixed `viewer/index.html` (the `main` version, run with the new test file): ``` node --test --test-name-pattern="read failure|body read that fails|valid manifest body still loads|test mode, a missing" tests/test_viewer_streaming.cjs # tests 3, pass 1, fail 2 # AssertionError: 'world/world.json could not be read as valid JSON.' does not match /could not be read\./ ``` The valid-body case also fails on the unfixed code, because its mock provides only `text()` and the old code calls `json()`. Not tested: a real browser. The viewer was not served or opened, so no page load, console or network check was done. The change is inside `loadWorld()`, which runs once at startup. No GPU, no game files. AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#955
No description provided.