From 6823c5eeddf5df585ed4dbd86d4a386f054c0a09 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 17 Apr 2024 09:11:35 -0700 Subject: [PATCH] fix errors engine inlined (#2152) Signed-off-by: Jess Frazelle --- e2e/playwright/flow-tests.spec.ts | 50 +++++++++++++++++++++++++++++++ src/lang/std/engineConnection.ts | 19 +++++++++--- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/e2e/playwright/flow-tests.spec.ts b/e2e/playwright/flow-tests.spec.ts index e5402146b..036e1b3b1 100644 --- a/e2e/playwright/flow-tests.spec.ts +++ b/e2e/playwright/flow-tests.spec.ts @@ -328,6 +328,56 @@ test('if you write invalid kcl you get inlined errors', async ({ page }) => { await expect(page.locator('.cm-lint-marker-error')).not.toBeVisible() }) +test('if your kcl gets an error from the engine it is inlined', async ({ + page, +}) => { + const u = getUtils(page) + await page.addInitScript(async () => { + localStorage.setItem( + 'persistCode', + `const box = startSketchOn('XY') +|> startProfileAt([0, 0], %) +|> line([0, 10], %) +|> line([10, 0], %) +|> line([0, -10], %, 'revolveAxis') +|> close(%) +|> extrude(10, %) + +const sketch001 = startSketchOn(box, "revolveAxis") +|> startProfileAt([5, 10], %) +|> line([0, -10], %) +|> line([2, 0], %) +|> line([0, 10], %) +|> close(%) +|> revolve({ +axis: getEdge('revolveAxis', box), +angle: 90 +}, %) + ` + ) + }) + + await page.setViewportSize({ width: 1000, height: 500 }) + await page.goto('/') + + await u.waitForAuthSkipAppStart() + + u.openDebugPanel() + await u.expectCmdLog('[data-message-type="execution-done"]') + await u.closeDebugPanel() + + // error in guter + await expect(page.locator('.cm-lint-marker-error')).toBeVisible() + + // error text on hover + await page.hover('.cm-lint-marker-error') + await expect( + page.getByText( + 'sketch profile must lie entirely on one side of the revolution axis' + ) + ).toBeVisible() +}) + test('executes on load', async ({ page }) => { const u = getUtils(page) await page.addInitScript(async () => { diff --git a/src/lang/std/engineConnection.ts b/src/lang/std/engineConnection.ts index dd0c5d9dc..22fd51db2 100644 --- a/src/lang/std/engineConnection.ts +++ b/src/lang/std/engineConnection.ts @@ -1068,7 +1068,7 @@ export class EngineCommandManager { message.request_id && this.artifactMap[message.request_id] ) { - this.handleFailedModelingCommand(message) + this.handleFailedModelingCommand(message.request_id, message) } } }) @@ -1247,14 +1247,12 @@ export class EngineCommandManager { } } } - handleFailedModelingCommand(raw: WebSocketResponse) { - const id = raw.request_id + handleFailedModelingCommand(id: string, raw: WebSocketResponse) { const failed = raw as Models['FailureWebSocketResponse_type'] const errors = failed.errors if (!id) return const command = this.artifactMap[id] if (command && command.type === 'pending') { - const resolve = command.resolve this.artifactMap[id] = { type: 'failed', range: command.range, @@ -1263,6 +1261,19 @@ export class EngineCommandManager { parentId: command.parentId ? command.parentId : undefined, errors, } + if ( + command?.type === 'pending' && + command.commandType === 'batch' && + command?.additionalData?.type === 'batch-ids' + ) { + command.additionalData.ids.forEach((id) => { + this.handleFailedModelingCommand(id, raw) + }) + } + // batch artifact is just a container, we don't need to keep it + // once we process all the commands inside it + const resolve = command.resolve + delete this.artifactMap[id] resolve({ id, commandType: command.commandType,