Repository navigation
Fix app dev exiting on non-JSON extensions WebSocket messages - #9040
Conversation
alexanderMontague
left a comment
There was a problem hiding this comment.
Approving — the fix is correct for what it claims. A SyntaxError thrown inside the message listener is an uncaught exception (it never becomes a socket error event, so #9039 doesn't cover it), and rethrowing non-SyntaxErrors is the right call.
One suggestion worth doing here rather than in a third PR: the guard only catches invalid JSON. Valid JSON with the wrong shape still throws a TypeError from the same listener and exits app dev. I checked these against the handler logic:
null→Cannot destructure property 'event' of 'jsonData' as it is null{"event":"log"}→Cannot read properties of undefined (reading 'extensionName'){"event":"update"}→Cannot read properties of undefined (reading 'app')
A small extension closes this: after parsing, return early unless jsonData is a non-null object, and treat a missing data on log/update as ignorable.
Process nit: this and #9039 are both branched from main, touch the same two files, and fix the same "misbehaving client kills app dev" problem. I confirmed they merge cleanly together, so this is only a question of whether one PR would be easier to review and release-note.
Generated with Pi. Vetted by Me.
getOnMessageHandler called JSON.parse on every incoming message without a try/catch. When a client sent a text message that is not valid JSON, the SyntaxError escaped the socket's message listener as an uncaught exception and `app dev` exited. Catch the SyntaxError, log it with outputDebug, and ignore the message. Add a regression test in handlers.test.ts. Co-authored-by: Isaac Roldan <isaac.roldan@shopify.com>
3c40fdd to
574eac5
Compare
WHY are these changes introduced?
shopify app devexits when a client of the/extensionsWebSocket sends a text message that is not valid JSON.getOnMessageHandlerinpackages/app/src/cli/services/dev/extension/websocket/handlers.tscallsJSON.parseon every message without atry/catch. TheSyntaxErrorescapes the socket'smessagelistener as an uncaught exception, and the process stops.WHAT is this pull request doing?
SyntaxErrorfromJSON.parse, logs it withoutputDebug, and ignores the message. Other errors still propagate.handlers.test.tsfor a message that is not JSON.@shopify/app.Before, a client that sends
not jsonstops the dev session:After, the session continues. With
--verbose, the CLI prints:How to manually test your changes?
shopify app dev --verbosein an app with a UI extension./extensions, for examplenpx wscat -c ws://localhost:<port>/extensions.not json.app devkeeps running and prints the debug line above.{"event":"dispatch","data":{"type":"focus","extensions":[]}}, and confirm that the connected clients receive it.Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add