Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: add error logging, safe path conversion, and try/catch for recordings folder commands

ManthanNimodiyab9df99c1ec32
diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs
index df0c67f59..4a0a3efa8 100644
--- a/apps/desktop/src-tauri/src/general_settings.rs
+++ b/apps/desktop/src-tauri/src/general_settings.rs
@@ -333,6 +333,7 @@ pub enum AppTheme {
impl GeneralSettingsStore {
pub fn recordings_dir(app: &AppHandle<Wry>) -> std::path::PathBuf {
let custom = Self::get(app)
+ .map_err(|e| tracing::warn!("Failed to read general settings for recordings_dir: {e}"))
.ok()
.flatten()
.and_then(|s| s.recordings_path)
@@ -344,7 +345,9 @@ impl GeneralSettingsStore {
let path = custom.unwrap_or_else(|| {
app.path().app_data_dir().unwrap().join("recordings")
});
- std::fs::create_dir_all(&path).unwrap_or_default();
+ if let Err(e) = std::fs::create_dir_all(&path) {
+ tracing::warn!(?path, %e, "Failed to create recordings directory");
+ }
path
}
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index b508c8905..10610701f 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -4269,7 +4269,8 @@ async fn pick_recordings_folder(app: AppHandle) -> Result<Option<String>, String
let _ = tx.send(
path.as_ref()
.and_then(|p| p.as_path())
- .map(|p| p.to_string_lossy().to_string()),
+ .and_then(|p| p.to_str())
+ .map(|s| s.to_string()),
);
});
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
index 34fa10f3b..e5796f8bd 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
@@ -642,14 +642,22 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
<StorageSection
recordingsPath={settings.recordingsPath ?? null}
onPick={async () => {
- const path = await commands.pickRecordingsFolder();
- if (path !== null) {
- setSettings("recordingsPath", path);
+ try {
+ const path = await commands.pickRecordingsFolder();
+ if (path !== null) {
+ setSettings("recordingsPath", path);
+ }
+ } catch (e) {
+ toast.error(`Failed to choose recordings folder: ${e instanceof Error ? e.message : String(e)}`);
}
}}
onReset={async () => {
- await commands.resetRecordingsFolder();
- setSettings("recordingsPath", null);
+ try {
+ await commands.resetRecordingsFolder();
+ setSettings("recordingsPath", null);
+ } catch (e) {
+ toast.error(`Failed to reset recordings folder: ${e instanceof Error ? e.message : String(e)}`);
+ }
}}
/>