From 39bc1971370d3633c6f2307bde110f7723b91fb4 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 16 Mar 2025 17:23:11 -0300 Subject: [PATCH] fallback to empty store if failed to load --- plugins/http/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/http/src/lib.rs b/plugins/http/src/lib.rs index 5e017c80..921f7969 100644 --- a/plugins/http/src/lib.rs +++ b/plugins/http/src/lib.rs @@ -4,6 +4,8 @@ //! Access the HTTP client written in Rust. +use std::io::Cursor; + pub use reqwest; use tauri::{ plugin::{Builder, TauriPlugin}, @@ -46,7 +48,15 @@ pub fn init() -> TauriPlugin { .open(&path)?; let reader = BufReader::new(file); - let store = CookieStoreMutex::load(reader).map_err(|e| e.to_string())?; + let store = CookieStoreMutex::load(reader) + .or_else(|_e| { + #[cfg(feature = "tracing")] + tracing::warn!( + "failed to load cookie store: {_e}, falling back to empty store" + ); + CookieStoreMutex::load(Cursor::new("[]".to_string())) + }) + .map_err(|e| e.to_string())?; (path, Arc::new(store)) };