Skip to content

fix(desktop): wrap get_dev_key invoke in try/catch for release builds#167

Merged
FSM1 merged 1 commit into
mainfrom
fix/desktop-init-and-isloading
Feb 20, 2026
Merged

fix(desktop): wrap get_dev_key invoke in try/catch for release builds#167
FSM1 merged 1 commit into
mainfrom
fix/desktop-init-and-isloading

Conversation

@FSM1

@FSM1 FSM1 commented Feb 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • get_dev_key is only registered as a Tauri command in debug builds (#[cfg(debug_assertions)] in main.rs), but the webview JS called await invoke('get_dev_key') without try/catch
  • In release builds (e.g. staging DMG), the promise rejects immediately, silently aborting the entire init() function — leaving the app stuck on "Initializing CipherBox..." forever
  • Fix: wrap the invoke in try/catch so it gracefully returns null in release builds

Test plan

  • Desktop release build (staging DMG) progresses past "Initializing CipherBox..." to the login screen
  • Desktop debug build with --dev-key still works as before

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Enhanced application stability by gracefully handling missing development key features in release builds, preventing potential crashes when development tools are unavailable.

get_dev_key is only registered in the Tauri command handler for debug
builds (#[cfg(debug_assertions)]). In release builds, the invoke()
promise rejects with an unhandled error, causing the entire init()
function to abort silently — leaving the webview stuck on
"Initializing CipherBox..." forever.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 20, 2026

Copy link
Copy Markdown

Walkthrough

The change adds try/catch error handling around a dev-key retrieval call in the main application initialization, initializing the devKey variable to null and gracefully handling cases where the command is unavailable in certain build configurations.

Changes

Cohort / File(s) Summary
Error Handling for Dev-Key Retrieval
apps/desktop/src/main.ts
Wrapped dev-key retrieval in try/catch block with null initialization to prevent unhandled rejections when the command is not registered (e.g., in release builds).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: wrapping get_dev_key invoke in try/catch for release builds, which is exactly what the PR accomplishes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/desktop-init-and-isloading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FSM1 FSM1 enabled auto-merge (squash) February 20, 2026 00:06
@FSM1 FSM1 merged commit 1699b5e into main Feb 20, 2026
8 of 9 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/desktop/src/main.ts (1)

51-58: Fix is correct; consider a debug-mode fallback log in the catch.

The try/catch properly resolves the release-build regression. One minor gap: the bare catch {} silently discards all errors, including unexpected IPC failures in debug builds. If get_dev_key fails for a reason unrelated to "command not registered" (e.g., a Tauri IPC misconfiguration during development), the error disappears and the dev has no signal that the --dev-key flow was skipped unexpectedly.

♻️ Optional: surface unexpected errors in debug builds
-  try {
-    devKey = await invoke('get_dev_key');
-  } catch {
-    // Expected in release builds where the command isn't registered
-  }
+  try {
+    devKey = await invoke<string | null>('get_dev_key');
+  } catch (err) {
+    // Expected in release builds where the command isn't registered.
+    // Log in debug so unexpected IPC failures don't silently drop --dev-key.
+    if (import.meta.env.DEV) {
+      console.warn('get_dev_key invoke failed (expected in release builds):', err);
+    }
+  }

The explicit invoke<string | null> generic is also slightly clearer than relying on contextual type inference from the devKey assignment, though both compile correctly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/desktop/src/main.ts` around lines 51 - 58, The empty catch swallows all
IPC errors; change the invoke call to invoke<string | null>('get_dev_key') and
in the catch block log unexpected errors when in debug/dev mode (e.g., check a
debug flag or NODE_ENV) so IPC failures during development are surfaced, while
still allowing a silent fallback in release builds; reference the devKey
variable, the invoke('get_dev_key') call and the surrounding try/catch to locate
where to add the conditional debug log.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/desktop/src/main.ts`:
- Around line 51-58: The empty catch swallows all IPC errors; change the invoke
call to invoke<string | null>('get_dev_key') and in the catch block log
unexpected errors when in debug/dev mode (e.g., check a debug flag or NODE_ENV)
so IPC failures during development are surfaced, while still allowing a silent
fallback in release builds; reference the devKey variable, the
invoke('get_dev_key') call and the surrounding try/catch to locate where to add
the conditional debug log.

@FSM1 FSM1 deleted the fix/desktop-init-and-isloading branch February 21, 2026 06:17
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.

1 participant