Skip to content

refactor: resolve all no-floating-promises lint violations#13743

Merged
EurFelux merged 7 commits intomainfrom
eurfelux/refactor/no-floating-promises
Mar 24, 2026
Merged

refactor: resolve all no-floating-promises lint violations#13743
EurFelux merged 7 commits intomainfrom
eurfelux/refactor/no-floating-promises

Conversation

@EurFelux
Copy link
Copy Markdown
Collaborator

What this PR does

Before this PR:
The typescript/no-floating-promises lint rule was disabled ("off"), allowing 608 unhandled Promise expressions across 258 files.

After this PR:
The rule is enabled ("warn") and all 608 warnings are resolved. Async operations that genuinely needed await now have it; intentional fire-and-forget calls are explicitly marked with void.

Why we need it and why it was done in this way

Floating promises silently swallow errors and can cause hard-to-debug race conditions. Enabling this rule prevents future regressions.

A two-phase approach was used:

Phase 1 — Manual review (behavior change): Identified ~10 locations inside async functions where missing await was a potential bug, and added proper await:

  1. src/main/ipc.ts:

    • App_SetLaunchOnBoot handler → setAppLaunchOnBoot() is async (filesystem operations on Linux). Without await, errors were silently lost.
    • App_FlushAppData handler → cookies.flushStore() and closeAllConnections() return Promises. Without await, data flush was not guaranteed before the handler returned.
  2. src/main/services/SpanCacheService.ts:

    • cleanTopic()cleanHistoryTrace(), saveSpans(), and fs.rm() were not awaited, so cleanup could complete out of order or fail silently.
    • cleanLocalData() → Converted .then() chain to await for proper error propagation.

Phase 2 — Auto-fix (no behavior change): The remaining ~600 warnings were all in contexts where void is the correct and only fix:

  • Sync contexts (React event handlers, useEffect, useCallback) — cannot await
  • Fire-and-forget IPC (window.api.* from renderer) — by design
  • Queue operations (queue.add() in Redux thunks) — queue manages execution internally
  • Notifications (notificationService.send()) — non-critical
  • Electron shell/window (shell.openExternal(), loadURL(), loadFile()) — errors handled via Electron events

The following tradeoffs were made:
Using void for fire-and-forget calls makes intent explicit but does not add error handling. This preserves existing behavior while making the code self-documenting.

The following alternatives were considered:

  • Adding .catch() to all 600+ call sites — rejected because it would require deciding error handling logic for each site, and none of these were handling errors before.
  • Fixing everything manually — rejected as impractical for 600+ mechanical changes with no benefit over auto-fix.

Breaking changes

None. Phase 2 (void additions) has zero runtime behavior change. Phase 1 (await additions) fixes potential bugs but does not change the happy-path behavior.

Special notes for your reviewer

Focus review on the await additions (Phase 1) as these are the only behavior changes:

  • src/main/ipc.ts — 2 IPC handlers now properly await async operations
  • src/main/services/SpanCacheService.tscleanTopic() and cleanLocalData() now properly await filesystem operations

The remaining 256 files are mechanical void additions from oxlint --fix-suggestions — spot-check a few to confirm correctness, but exhaustive review is not needed.

Checklist

Release note

NONE

EurFelux and others added 6 commits March 23, 2026 21:49
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
Add proper await for async operations that need completion guarantees:
- ipc.ts: await setAppLaunchOnBoot, flushStore, closeAllConnections
- SpanCacheService.ts: await cleanHistoryTrace, saveSpans, fs operations

Add void for intentional fire-and-forget calls in sync contexts.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
…ooks, and store

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
…nents

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
…d windows

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: icarus <[email protected]>
Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This review was translated by Claude.

Code Review Summary

This PR high-quality resolved 608 no-floating-promises lint warnings.

Phase 1 (Behavior Changes) ✅

  • App_SetLaunchOnBoot: Correctly await async operations
  • App_FlushAppData: Ensure data flush completes before returning
  • SpanCacheService: Correctly await filesystem operations

Phase 2 (No Behavior Changes) ✅

  • ~600 void additions are all correct fire-and-forget patterns

CI passed, recommended to merge.


Original Content

代码审查总结

该 PR 高质量地解决了 608 个 no-floating-promises lint 警告。

Phase 1(行为变更)✅

  • App_SetLaunchOnBoot: 正确 await async 操作
  • App_FlushAppData: 确保数据刷新完成后再返回
  • SpanCacheService: 正确 await 文件系统操作

Phase 2(无行为变更)✅

  • ~600 处 void 添加均为正确的 fire-and-forget 模式

CI 通过,推荐合并。

@EurFelux EurFelux merged commit 0a7a2b9 into main Mar 24, 2026
5 checks passed
@EurFelux EurFelux deleted the eurfelux/refactor/no-floating-promises branch March 24, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants