Skip to content

fix(recording): replace blocking dialog with toast for mic not available errors#1974

Merged
richiemcilroy merged 1 commit into
CapSoftware:mainfrom
ManthanNimodiya:fix/device-not-found-toast-error
Jul 2, 2026
Merged

fix(recording): replace blocking dialog with toast for mic not available errors#1974
richiemcilroy merged 1 commit into
CapSoftware:mainfrom
ManthanNimodiya:fix/device-not-found-toast-error

Conversation

@ManthanNimodiya

@ManthanNimodiya ManthanNimodiya commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

When the selected mic isn't available, a blocking native dialog caused a loop on multi-monitor setups, user dismisses, overlay re-appears, clicks again, repeat 5-7 times.

Fix: catch startRecording errors in the overlay and show a toast instead.
Skip the blocking dialog in handle_spawn_failure for DeviceNotFound so the overlay stays interactive.

Greptile Summary

This PR fixes a UX loop on multi-monitor setups where a blocking native dialog for mic-unavailable errors would repeatedly re-appear after dismissal. It replaces that dialog with a non-blocking toast on the frontend and suppresses the native dialog in the Rust backend for DeviceNotFound errors.

  • recording.rs: handle_spawn_failure now skips the MessageDialogBuilder / blocking_show path when the error message contains "no longer available" or "DeviceNotFound", keeping the overlay interactive.
  • target-select-overlay.tsx: A .catch handler is added to the startRecording call that shows a friendly toast for mic errors and a generic fallback for any other rejection; the same two substrings are checked independently on this side, creating a duplicated classification that could drift if either side is updated.

Confidence Score: 4/5

Safe to merge — the change addresses a real, reproducible loop and the fallback path (generic toast) is still shown for any unrecognised error.

Both changed files have contained, low-risk edits. The only concerns are that the two substring guards are independently maintained in Rust and TypeScript, and the new catch block lacks a console.error call. Neither affects correctness today.

The string-matching in recording.rs and target-select-overlay.tsx should stay in sync; if the underlying audio library changes its error messages, one side will diverge silently.

Important Files Changed

Filename Overview
apps/desktop/src-tauri/src/recording.rs Wraps the blocking native dialog in a condition that skips it for DeviceNotFound errors (detected via substring match), allowing the recording overlay to remain interactive; duplicates the same substrings checked on the TypeScript side.
apps/desktop/src/routes/target-select-overlay.tsx Adds a .catch handler to startRecording that shows a user-friendly toast for mic-unavailable errors and a generic fallback for others; missing console.error logging and duplicates the Rust-side string matching.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/desktop/src-tauri/src/recording.rs:2373-2376
**Duplicate string-matching across Rust and TypeScript**

The same two substrings (`"no longer available"` and `"DeviceNotFound"`) are now hard-coded in both `recording.rs` (to suppress the native dialog) and `target-select-overlay.tsx` (to show the friendly toast). If the underlying audio library changes either error message, the two guards will diverge: the Rust side might still suppress the dialog while the TypeScript side falls through to the generic "Failed to start recording: …" message, or vice-versa. Centralising the classification — e.g., via a dedicated Tauri error variant instead of string matching — would make both sites resilient to message changes.

### Issue 2 of 2
apps/desktop/src/routes/target-select-overlay.tsx:1745-1766
Add `console.error` to match the pattern used by the screenshot error handler and other catch blocks in this file, so there is always a log trail even when the toast copy differs from the raw error.

```suggestion
								commands
									.startRecording({
										capture_target: props.target,
										mode: rawOptions.mode,
										capture_system_audio: rawOptions.captureSystemAudio,
									})
									.catch((e: unknown) => {
										console.error("Failed to start recording", e);
										const msg =
											e instanceof Error ? e.message : String(e);
										if (
											msg.includes("no longer available") ||
											msg.includes("DeviceNotFound")
										) {
											toast.error(
												"Selected microphone is not available. Please select a different microphone in settings.",
											);
										} else {
											toast.error(
												`Failed to start recording: ${msg}`,
											);
										}
									});
```

Reviews (1): Last reviewed commit: "fix(recording): show toast instead of bl..." | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Comment on lines +2375 to +2376
let is_device_not_found = message.contains("no longer available")
|| message.contains("DeviceNotFound");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The substring match here feels a bit brittle (casing/format can vary). Normalizing once keeps it from missing variants.

Suggested change
let is_device_not_found = message.contains("no longer available")
|| message.contains("DeviceNotFound");
let normalized_message = message.to_lowercase();
let is_device_not_found = normalized_message.contains("no longer available")
|| normalized_message.contains("devicenotfound");

Comment on lines +1752 to +1753
const msg =
e instanceof Error ? e.message : String(e);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Worth logging the underlying error here too (like the screenshot path does) so we don’t lose stack/context when users report this.

Suggested change
const msg =
e instanceof Error ? e.message : String(e);
const msg = e instanceof Error ? e.message : String(e);
console.error("Failed to start recording", e);

Comment on lines +1758 to +1760
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Given the original report mentions repeated clicks/loops, adding a stable id prevents a stack of identical toasts.

Suggested change
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
{ id: "mic-device-not-found" },
);

Comment on lines +1762 to +1764
toast.error(
`Failed to start recording: ${msg}`,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same idea for the generic failure path — stable id keeps the UI from getting flooded if this happens repeatedly.

Suggested change
toast.error(
`Failed to start recording: ${msg}`,
);
toast.error(
`Failed to start recording: ${msg}`,
{ id: "start-recording-failed" },
);

Comment on lines +2373 to +2376
// DeviceNotFound errors are surfaced to the user via the frontend toast; skip the
// blocking native dialog so the overlay stays responsive and the error isn't repeated.
let is_device_not_found = message.contains("no longer available")
|| message.contains("DeviceNotFound");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Duplicate string-matching across Rust and TypeScript

The same two substrings ("no longer available" and "DeviceNotFound") are now hard-coded in both recording.rs (to suppress the native dialog) and target-select-overlay.tsx (to show the friendly toast). If the underlying audio library changes either error message, the two guards will diverge: the Rust side might still suppress the dialog while the TypeScript side falls through to the generic "Failed to start recording: …" message, or vice-versa. Centralising the classification — e.g., via a dedicated Tauri error variant instead of string matching — would make both sites resilient to message changes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src-tauri/src/recording.rs
Line: 2373-2376

Comment:
**Duplicate string-matching across Rust and TypeScript**

The same two substrings (`"no longer available"` and `"DeviceNotFound"`) are now hard-coded in both `recording.rs` (to suppress the native dialog) and `target-select-overlay.tsx` (to show the friendly toast). If the underlying audio library changes either error message, the two guards will diverge: the Rust side might still suppress the dialog while the TypeScript side falls through to the generic "Failed to start recording: …" message, or vice-versa. Centralising the classification — e.g., via a dedicated Tauri error variant instead of string matching — would make both sites resilient to message changes.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +1745 to +1766
commands
.startRecording({
capture_target: props.target,
mode: rawOptions.mode,
capture_system_audio: rawOptions.captureSystemAudio,
})
.catch((e: unknown) => {
const msg =
e instanceof Error ? e.message : String(e);
if (
msg.includes("no longer available") ||
msg.includes("DeviceNotFound")
) {
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
} else {
toast.error(
`Failed to start recording: ${msg}`,
);
}
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Add console.error to match the pattern used by the screenshot error handler and other catch blocks in this file, so there is always a log trail even when the toast copy differs from the raw error.

Suggested change
commands
.startRecording({
capture_target: props.target,
mode: rawOptions.mode,
capture_system_audio: rawOptions.captureSystemAudio,
})
.catch((e: unknown) => {
const msg =
e instanceof Error ? e.message : String(e);
if (
msg.includes("no longer available") ||
msg.includes("DeviceNotFound")
) {
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
} else {
toast.error(
`Failed to start recording: ${msg}`,
);
}
});
commands
.startRecording({
capture_target: props.target,
mode: rawOptions.mode,
capture_system_audio: rawOptions.captureSystemAudio,
})
.catch((e: unknown) => {
console.error("Failed to start recording", e);
const msg =
e instanceof Error ? e.message : String(e);
if (
msg.includes("no longer available") ||
msg.includes("DeviceNotFound")
) {
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
} else {
toast.error(
`Failed to start recording: ${msg}`,
);
}
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/routes/target-select-overlay.tsx
Line: 1745-1766

Comment:
Add `console.error` to match the pattern used by the screenshot error handler and other catch blocks in this file, so there is always a log trail even when the toast copy differs from the raw error.

```suggestion
								commands
									.startRecording({
										capture_target: props.target,
										mode: rawOptions.mode,
										capture_system_audio: rawOptions.captureSystemAudio,
									})
									.catch((e: unknown) => {
										console.error("Failed to start recording", e);
										const msg =
											e instanceof Error ? e.message : String(e);
										if (
											msg.includes("no longer available") ||
											msg.includes("DeviceNotFound")
										) {
											toast.error(
												"Selected microphone is not available. Please select a different microphone in settings.",
											);
										} else {
											toast.error(
												`Failed to start recording: ${msg}`,
											);
										}
									});
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@richiemcilroy richiemcilroy merged commit 4d57af8 into CapSoftware:main Jul 2, 2026
12 of 17 checks passed
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