Skip to content

fix(ui-components): report invalid .phnx files instead of failing silently - #1033

Merged
EdwardMoyse merged 1 commit into
HSF:mainfrom
Shivansh1205:fix/phnx-invalid-json-silent-failure
Sep 16, 2026
Merged

EdwardMoyse merged 1 commit into
HSF:mainfrom
Shivansh1205:fix/phnx-invalid-json-silent-failure

Conversation

@Shivansh1205

@Shivansh1205 Shivansh1205 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1032

Problem

Loading a malformed .phnx file does nothing at all — no geometry, no error, no message.

Two things combine to swallow the failure:

  1. parsePhoenixDisplay is async and calls JSON.parse on the raw text, so a bad file produces a rejected promise, not a synchronous throw.
  2. handleSceneInput and handlePhoenixInput call it from inside the FileReader.onload callback without awaiting it or attaching a .catch.

Nothing observes the rejection. reader.onerror does 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 .phnx handlers were never given the same treatment.

Fix

Route both handlers through a parsePhoenixFile helper that reports the failure the same way the JSON handlers already do.

The helper deliberately handles both arrival paths:

try {
  Promise.resolve(this.eventDisplay.parsePhoenixDisplay(content)).catch(onError);
} catch (error) {
  onError(error);
}
  • .catch on the promise covers the actual bug — the async rejection.
  • The surrounding try covers anything thrown before the first await, so this stays correct if parsePhoenixDisplay ever becomes synchronous.

Promise.resolve(...) rather than await keeps the callback non-async, so handleFileInput's signature is untouched.

I kept the fix at the call site rather than adding a try/catch inside parsePhoenixDisplay, 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:

  • invalid .phnx via Load scene → reports an error, does not throw
  • invalid .phnx via Load Phoenix file → reports an error, does not throw
  • valid .phnx → still loads, and reports nothing

The existing tests for these handlers mock handleFileInput wholesale, 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 to handleFileInput and invoke it directly, exercising the real parse path without needing a live FileReader.

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 a try/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.

SyntaxError: Unexpected token 'o', "not json" is not valid JSON
    at JSON.parse (<anonymous>)
    ...
Node.js v24.14.0

(no test summary is printed — the process dies)

After the fix, all 16 tests in the suite pass.

Verification

  • Full phoenix-ng suite: 62 suites / 224 tests passed, 0 failures.
  • eslint clean on the io-options directory.
  • No pre-existing failures found, so none are carried here.

…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>
@github-actions

Copy link
Copy Markdown

🚀 Preview deployed: http://phoenix-pr-1033.surge.sh

Built from 89a1f01.

@EdwardMoyse
EdwardMoyse merged commit e1bd57d into HSF:main Sep 16, 2026
6 checks passed
@EdwardMoyse

Copy link
Copy Markdown
Member

Thank you very much for this, and the other PRs!

This branch was successfully deployed

1 active deployment
pull-request — 89a1f018 Deployed Sep 14, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid .phnx files fail silently: unhandled promise rejection in handleSceneInput / handlePhoenixInput

2 participants