From eebfd2ed3e4bae4ef195f20c992f01657a5f5121 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Tue, 9 Dec 2025 18:02:23 +0800 Subject: [PATCH] fix(store): error instead of panic on invalid rid (#3157) --- .changes/store-panic-on-invalid-rid.md | 6 ++++++ plugins/store/src/store.rs | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changes/store-panic-on-invalid-rid.md diff --git a/.changes/store-panic-on-invalid-rid.md b/.changes/store-panic-on-invalid-rid.md new file mode 100644 index 000000000..5b7223915 --- /dev/null +++ b/.changes/store-panic-on-invalid-rid.md @@ -0,0 +1,6 @@ +--- +"store": patch +"store-js": patch +--- + +Return an error instead of panic when the internally tracked resource id is invalid on creating new stores diff --git a/plugins/store/src/store.rs b/plugins/store/src/store.rs index f8b0c4604..8d86fb045 100644 --- a/plugins/store/src/store.rs +++ b/plugins/store/src/store.rs @@ -197,7 +197,10 @@ impl StoreBuilder { let _ = self.app.resources_table().take::>(rid); } } else if let Some(rid) = stores.get(&self.path) { - return Ok((self.app.resources_table().get(*rid).unwrap(), *rid)); + // The resource id we stored can be invalid due to + // the resource table getting modified by an external source + // (e.g. `App::cleanup_before_exit` > `manager.resources_table.clear()`) + return Ok((self.app.resources_table().get(*rid)?, *rid)); } // if stores.contains_key(&self.path) {