From c43704362960a11200ebf904fa87f8a4446faf4f Mon Sep 17 00:00:00 2001 From: Jakub Nyckowski Date: Mon, 5 Jun 2023 18:44:18 -0400 Subject: [PATCH 1/3] [Assist] Do not parse event data is there is none If there is no session data UI should not try to parse them, otherwise it will crash as this happens currently. --- web/packages/teleport/src/Assist/contexts/messages.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/packages/teleport/src/Assist/contexts/messages.tsx b/web/packages/teleport/src/Assist/contexts/messages.tsx index 657b07d3cbcba..af64030dc6954 100644 --- a/web/packages/teleport/src/Assist/contexts/messages.tsx +++ b/web/packages/teleport/src/Assist/contexts/messages.tsx @@ -256,11 +256,12 @@ async function convertServerMessage( const eventsData = (await eventsResp.json()) as { events: SessionEvent[]; }; - const execEvent = eventsData.events.find(isExecEvent); let msg; let errorMsg; if (sessionExists) { + // eventsData.events can be empty if the command execution failed. + const execEvent = eventsData.events.find(isExecEvent); // The offset here is set base on A/B test that was run between me, myself and I. const stream = await api.fetch( sessionUrl + '/stream?offset=0&bytes=4096', From d77a1bdabb1b6b77b79502415039b3ea2da3d303 Mon Sep 17 00:00:00 2001 From: Jakub Nyckowski Date: Mon, 5 Jun 2023 19:06:21 -0400 Subject: [PATCH 2/3] Move more code. --- web/packages/teleport/src/Assist/contexts/messages.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/packages/teleport/src/Assist/contexts/messages.tsx b/web/packages/teleport/src/Assist/contexts/messages.tsx index af64030dc6954..8117bf4254321 100644 --- a/web/packages/teleport/src/Assist/contexts/messages.tsx +++ b/web/packages/teleport/src/Assist/contexts/messages.tsx @@ -88,6 +88,7 @@ interface ExecEvent { event: EventType.EXEC; exitError?: string; } + type SessionEvent = ExecEvent | { event: string }; const convertToQuery = (cmd: ExecuteRemoteCommandPayload): string => { @@ -253,14 +254,15 @@ async function convertServerMessage( const eventsResp = await api.fetch(sessionUrl + '/events'); const sessionExists = eventsResp.status === 200; - const eventsData = (await eventsResp.json()) as { - events: SessionEvent[]; - }; let msg; let errorMsg; if (sessionExists) { - // eventsData.events can be empty if the command execution failed. + // Get events only if the session exists. Otherwise, eventsData.events can be empty + // if the command execution failed. + const eventsData = (await eventsResp.json()) as { + events: SessionEvent[]; + }; const execEvent = eventsData.events.find(isExecEvent); // The offset here is set base on A/B test that was run between me, myself and I. const stream = await api.fetch( From a529981e329da44d0737fb52cd90499f3cf9af67 Mon Sep 17 00:00:00 2001 From: Jakub Nyckowski Date: Mon, 5 Jun 2023 19:23:58 -0400 Subject: [PATCH 3/3] Update web/packages/teleport/src/Assist/contexts/messages.tsx Co-authored-by: Lisa Kim --- web/packages/teleport/src/Assist/contexts/messages.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/packages/teleport/src/Assist/contexts/messages.tsx b/web/packages/teleport/src/Assist/contexts/messages.tsx index 8117bf4254321..3bd919135fbf5 100644 --- a/web/packages/teleport/src/Assist/contexts/messages.tsx +++ b/web/packages/teleport/src/Assist/contexts/messages.tsx @@ -263,7 +263,7 @@ async function convertServerMessage( const eventsData = (await eventsResp.json()) as { events: SessionEvent[]; }; - const execEvent = eventsData.events.find(isExecEvent); + const execEvent = eventsData.events?.find(isExecEvent); // The offset here is set base on A/B test that was run between me, myself and I. const stream = await api.fetch( sessionUrl + '/stream?offset=0&bytes=4096',