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