fix(ui-components): report invalid .phnx files instead of failing silently - #1033
Merged
EdwardMoyse merged 1 commit intoSep 16, 2026
Merged
Conversation
…ently `parsePhoenixDisplay` calls `JSON.parse` on the raw file text. It is `async`, so a malformed file surfaces as a rejected promise rather than a synchronous throw, and `handleSceneInput` / `handlePhoenixInput` call it from inside the `FileReader.onload` callback without awaiting it. Nothing handles the rejection: `reader.onerror` fires only for read failures, not for a callback that rejects. The user picks a .phnx file, presses the button, and nothing happens at all - no geometry, no error, no message. A truncated download or a file saved from the wrong export both land here, and the UI gives no indication why. The sibling handlers in this same dialog already guard their parses and report the problem through the info logger and a notification. Route both .phnx handlers through a `parsePhoenixFile` helper that does the same. The helper catches both ways the failure can arrive: `.catch` on the returned promise for the rejection, and a surrounding `try` for anything thrown before the first await, so it stays correct if `parsePhoenixDisplay` later becomes synchronous. Added tests driving the real callback. The existing suite mocks `handleFileInput` wholesale, so the parse path never ran and the bug was invisible to it; these capture the callback and invoke it. Before this change the unhandled rejection aborts the Node worker outright rather than merely failing an assertion. Fixes HSF#1032 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
🚀 Preview deployed: http://phoenix-pr-1033.surge.sh Built from 89a1f01. |
Member
|
Thank you very much for this, and the other PRs! |
This branch was successfully deployed
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 #1032
Problem
Loading a malformed
.phnxfile does nothing at all — no geometry, no error, no message.Two things combine to swallow the failure:
parsePhoenixDisplayisasyncand callsJSON.parseon the raw text, so a bad file produces a rejected promise, not a synchronous throw.handleSceneInputandhandlePhoenixInputcall it from inside theFileReader.onloadcallback without awaiting it or attaching a.catch.Nothing observes the rejection.
reader.onerrordoes not help — it fires when the read fails, not when the onload callback rejects. That read-failure path is what #767 added; this is the other failure mode.It is also inconsistent within this very file: the sibling JSON handlers (
handleJSONEventDataInput,handleEDM4HEPJSONEventDataInput) already catch malformed input and report it through the info logger plus a notification. The.phnxhandlers were never given the same treatment.Fix
Route both handlers through a
parsePhoenixFilehelper that reports the failure the same way the JSON handlers already do.The helper deliberately handles both arrival paths:
.catchon the promise covers the actual bug — the async rejection.trycovers anything thrown before the first await, so this stays correct ifparsePhoenixDisplayever becomes synchronous.Promise.resolve(...)rather thanawaitkeeps the callback non-async, sohandleFileInput's signature is untouched.I kept the fix at the call site rather than adding a
try/catchinsideparsePhoenixDisplay, because that method has no access to the notification service and its other callers may want the rejection to propagate. This matches where the existing JSON guards live.Tests
Added three cases to the existing suite:
.phnxvia Load scene → reports an error, does not throw.phnxvia Load Phoenix file → reports an error, does not throw.phnx→ still loads, and reports nothingThe existing tests for these handlers mock
handleFileInputwholesale, so the callback never runs and this path was entirely untested — which is why the bug was invisible to CI. The new tests capture the callback that the handler passes tohandleFileInputand invoke it directly, exercising the real parse path without needing a liveFileReader.The mock is
async (content) => JSON.parse(content), reproducing the real method's shape: the parse failure arrives as a rejection, not a sync throw. An earlier draft of these tests used a synchronously-throwing mock and passed against atry/catch-only fix — the async mock is what actually pins the bug.Before this change the two invalid-file tests do not merely fail an assertion: the unhandled rejection aborts the Jest worker outright.
(no test summary is printed — the process dies)
After the fix, all 16 tests in the suite pass.
Verification
phoenix-ngsuite: 62 suites / 224 tests passed, 0 failures.eslintclean on theio-optionsdirectory.