From 3e4505e2e3948086f97774a51ed42c60b5d24f01 Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Wed, 2 Apr 2025 22:53:10 -0400 Subject: [PATCH] [refactor] remove 6 floating-promise ignores (#5985) * Remove trivial floating promise in authMachine * Add catch statement so LSP promise is considered non-floating * Remove trivial float in AllSettingsFields * Add error reporting for ensureWasmInit * Remove pointless floating promise in Modeling * Add comment and reportRejection to floating promise in "set selection" * Read comment, put back await that should be there * Fix dumb imports rebase botch * Missed an import --------- Co-authored-by: Jess Frazelle --- src/components/ModelingMachineProvider.tsx | 13 ++++++++----- src/components/Settings/AllSettingsFields.tsx | 3 +-- src/editor/plugins/lsp/worker.ts | 13 ++++++++----- src/lib/rustContext.ts | 11 ++++++----- src/machines/authMachine.ts | 5 +++-- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/components/ModelingMachineProvider.tsx b/src/components/ModelingMachineProvider.tsx index 33dcd4893..673692664 100644 --- a/src/components/ModelingMachineProvider.tsx +++ b/src/components/ModelingMachineProvider.tsx @@ -445,10 +445,15 @@ export const ModelingMachineProvider = ({ }, }) } + + // If there are engine commands that need sent off, send them + // TODO: This should be handled outside of an action as its own + // actor, so that the system state is more controlled. engineEvents && engineEvents.forEach((event) => { - // eslint-disable-next-line @typescript-eslint/no-floating-promises - engineCommandManager.sendSceneCommand(event) + engineCommandManager + .sendSceneCommand(event) + .catch(reportRejection) }) updateSceneObjectColors() @@ -1566,9 +1571,7 @@ export const ModelingMachineProvider = ({ data ) if (err(result)) return reject(result) - - // eslint-disable-next-line @typescript-eslint/no-floating-promises - codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast) + await codeManager.updateEditorWithAstAndWriteToFile(kclManager.ast) return result } diff --git a/src/components/Settings/AllSettingsFields.tsx b/src/components/Settings/AllSettingsFields.tsx index 02c33f974..fbfe911d8 100644 --- a/src/components/Settings/AllSettingsFields.tsx +++ b/src/components/Settings/AllSettingsFields.tsx @@ -96,8 +96,7 @@ export const AllSettingsFields = forwardRef( } } } - // eslint-disable-next-line @typescript-eslint/no-floating-promises - navigateToOnboardingStart() + navigateToOnboardingStart().catch(reportRejection) }, [ isFileSettings, navigate, diff --git a/src/editor/plugins/lsp/worker.ts b/src/editor/plugins/lsp/worker.ts index ec80718d0..3893c0615 100644 --- a/src/editor/plugins/lsp/worker.ts +++ b/src/editor/plugins/lsp/worker.ts @@ -102,11 +102,14 @@ onmessage = function (event: MessageEvent) { intoServer.enqueue(data) const json: jsrpc.JSONRPCRequest = Codec.decode(data) if (null != json.id) { - // eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-non-null-assertion - fromServer.responses.get(json.id)!.then((response) => { - const encoded = Codec.encode(response as jsrpc.JSONRPCResponse) - postMessage(encoded) - }) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + fromServer.responses + .get(json.id)! + .then((response) => { + const encoded = Codec.encode(response as jsrpc.JSONRPCResponse) + postMessage(encoded) + }) + .catch(reportRejection) } break default: diff --git a/src/lib/rustContext.ts b/src/lib/rustContext.ts index 2dc549108..05eafed8c 100644 --- a/src/lib/rustContext.ts +++ b/src/lib/rustContext.ts @@ -20,7 +20,7 @@ import { import type ModelingAppFile from '@src/lib/modelingAppFile' import type { DefaultPlaneStr } from '@src/lib/planes' import { defaultPlaneStrToKey } from '@src/lib/planes' -import { err } from '@src/lib/trap' +import { err, reportRejection } from '@src/lib/trap' import type { DeepPartial } from '@src/lib/types' import type { ModuleType } from '@src/lib/wasm_lib_wrapper' import { getModule } from '@src/lib/wasm_lib_wrapper' @@ -48,10 +48,11 @@ export default class RustContext { constructor(engineCommandManager: EngineCommandManager) { this.engineCommandManager = engineCommandManager - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.ensureWasmInit().then(async () => { - this.ctxInstance = await this.create() - }) + this.ensureWasmInit() + .then(async () => { + this.ctxInstance = await this.create() + }) + .catch(reportRejection) } // Create a new context instance diff --git a/src/machines/authMachine.ts b/src/machines/authMachine.ts index 66507e7f7..7061128bf 100644 --- a/src/machines/authMachine.ts +++ b/src/machines/authMachine.ts @@ -238,8 +238,9 @@ async function getAndSyncStoredToken(input: { if (token) { // has just logged in, update storage localStorage.setItem(TOKEN_PERSIST_KEY, token) - // eslint-disable-next-line @typescript-eslint/no-floating-promises - isDesktop() && writeTokenFile(token) + if (isDesktop()) { + await writeTokenFile(token) + } return token } if (!isDesktop()) return ''