From d40ff6187016f269b78c11c0172c7ac26526de36 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Wed, 16 Mar 2022 16:39:23 -0700 Subject: [PATCH] Recover from args argument being uniterable Summary: Another kind of error that can easily be triggered during testing that will kill the server otherwise. Changelog: Make it possible to recover from malformed JSON in server requests Reviewed By: timur-valiev Differential Revision: D34932896 fbshipit-source-id: 7c6acfd53ffbd85a54a786d74c99bcccb64d85cb --- desktop/flipper-server/src/startSocketServer.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/desktop/flipper-server/src/startSocketServer.tsx b/desktop/flipper-server/src/startSocketServer.tsx index 4ce0be163..6cd2a102c 100644 --- a/desktop/flipper-server/src/startSocketServer.tsx +++ b/desktop/flipper-server/src/startSocketServer.tsx @@ -65,6 +65,21 @@ export function startSocketServer( case 'exec': { const {id, command, args} = payload; + if (typeof args[Symbol.iterator] !== 'function') { + console.warn( + 'flipperServer -> exec: args argument in payload is not iterable', + ); + const responseError: ExecResponseErrorWebSocketMessage = { + event: 'exec-response-error', + payload: { + id, + data: 'Payload args argument is not an iterable.', + }, + }; + client.send(JSON.stringify(responseError)); + return; + } + flipperServer .exec(command, ...args) .then((result: any) => {