Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions apps/desktop/src-tauri/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,18 +2370,25 @@ async fn handle_spawn_failure(
}
.emit(app);

let mut dialog = MessageDialogBuilder::new(
app.dialog().clone(),
"An error occurred".to_string(),
message.clone(),
)
.kind(tauri_plugin_dialog::MessageDialogKind::Error);
// 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");
Comment on lines +2375 to +2376

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 +2373 to +2376

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!


if !is_device_not_found {
let mut dialog = MessageDialogBuilder::new(
app.dialog().clone(),
"An error occurred".to_string(),
message.clone(),
)
.kind(tauri_plugin_dialog::MessageDialogKind::Error);

if let Some(window) = CapWindowId::RecordingControls.get(app) {
dialog = dialog.parent(&window);
}
if let Some(window) = CapWindowId::RecordingControls.get(app) {
dialog = dialog.parent(&window);
}

dialog.blocking_show();
dialog.blocking_show();
}

let mut state = state_mtx.write().await;
let _ = handle_recording_end(
Expand Down
27 changes: 22 additions & 5 deletions apps/desktop/src/routes/target-select-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1742,11 +1742,28 @@ function RecordingControls(props: {
return;
}

commands.startRecording({
capture_target: props.target,
mode: rawOptions.mode,
capture_system_audio: rawOptions.captureSystemAudio,
});
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);
Comment on lines +1752 to +1753

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);

if (
msg.includes("no longer available") ||
msg.includes("DeviceNotFound")
) {
toast.error(
"Selected microphone is not available. Please select a different microphone in settings.",
);
Comment on lines +1758 to +1760

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" },
);

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

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 +1745 to +1766

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!

}}
>
<div
Expand Down
Loading