Skip to content

Handle microphone init failure without aborting#945

Merged
cjpais merged 4 commits intocjpais:mainfrom
ferologics:fix/windows-mic-init-crash
Mar 10, 2026
Merged

Handle microphone init failure without aborting#945
cjpais merged 4 commits intocjpais:mainfrom
ferologics:fix/windows-mic-init-crash

Conversation

@ferologics
Copy link
Copy Markdown
Contributor

Summary

This PR prevents a hard crash when microphone stream initialization fails (for example, when Windows microphone privacy blocks access).

What changed

  • src-tauri/src/audio_toolkit/audio/recorder.rs
    • Replaced panic paths in AudioRecorder::open (expect/unwrap/panic) with explicit error propagation.
    • Added a startup handshake channel so open() only succeeds after worker initialization succeeds.
    • Converted known permission-denied errors into a clearer user/actionable message.
  • src-tauri/src/actions.rs
    • When recording fails to start, immediately restore UI state by hiding the recording overlay and setting tray icon back to idle.

Why

In release builds (panic = "abort"), panic paths during recorder startup can terminate the process. This keeps startup failure as a normal error path instead.

Refs #436

Return recorder init errors instead of panicking/aborting in the worker thread and reset UI state when recording start fails.

Refs cjpais#436
@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Mar 3, 2026

@ferologics have you tested this yourself to verify?

Just want to make sure. Also do you know if the UI visibly says anything about this failure case?

@ferologics
Copy link
Copy Markdown
Contributor Author

@cjpais i wasn't able to make handy run locally from source (ref) so i couldn't test.

I came across the crash due to having disabled microphone globally via settings.

Tried to make this change isolated to that, not touching any UI. Onboarding / in-app hints about disabled mic could made be better tho.

Right now when the crash happens it briefly shows the recording UI and then it disappears, no info in the app / anywhere about it.

@ferologics
Copy link
Copy Markdown
Contributor Author

re: the microphone access denied bit -- it comes directly from my local agent. i had it check the crash log, look at current system settings configuration and patch that particular case in handy.

@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Mar 3, 2026

Got it, I am going to push some changes for the UI I think. Let's get your build env fixed

@ferologics
Copy link
Copy Markdown
Contributor Author

Tested locally now.

Repro:

  • launched Handy from source on Windows
  • disabled microphone access in Settings -> Privacy & security -> Microphone
  • pressed the transcribe hotkey repeatedly

Result:

  • Handy no longer crashes
  • the app stays alive/running
  • repeated hotkey presses are handled safely
  • logs show the normalized microphone access denied error path firing as expected

So the crash-path fix is working on my machine now.

Current UX is much better than before: the recording UI briefly appears and then resets instead of aborting the app, and the PR's UI follow-up now propagates the error to the frontend.

I think there is still room for polish in a follow-up (for example a more explicit microphone-blocked message/icon), but the main bug here appears fixed.

@ferologics
Copy link
Copy Markdown
Contributor Author

image

@ferologics
Copy link
Copy Markdown
Contributor Author

ferologics commented Mar 8, 2026

I would have expected the error to surface closer to the recording indicator / overlay, so I initially missed it. That said, I think this is fine for this PR: the crash is fixed, the error is handled, and there is now a visible path for surfacing it. A more contextual microphone-blocked warning could be a separate follow-up if we want to polish it later.

@cjpais
Copy link
Copy Markdown
Owner

cjpais commented Mar 10, 2026

Thank you for this!

I suspect it may also fix: #475

@cjpais cjpais merged commit 785c331 into cjpais:main Mar 10, 2026
4 checks passed
fxbenard pushed a commit to fxbenard/Parler that referenced this pull request Mar 11, 2026
* Handle microphone start failures without aborting

Return recorder init errors instead of panicking/aborting in the worker thread and reset UI state when recording start fails.

Refs cjpais#436

* prop errors to ui

* format

* Add missing recording error translation keys

---------

Co-authored-by: CJ Pais <[email protected]>
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.

2 participants