Skip to content

Commit eebfd2e

Browse files
fix(store): error instead of panic on invalid rid (#3157)
1 parent 521cd8b commit eebfd2e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"store": patch
3+
"store-js": patch
4+
---
5+
6+
Return an error instead of panic when the internally tracked resource id is invalid on creating new stores

plugins/store/src/store.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ impl<R: Runtime> StoreBuilder<R> {
197197
let _ = self.app.resources_table().take::<Store<R>>(rid);
198198
}
199199
} else if let Some(rid) = stores.get(&self.path) {
200-
return Ok((self.app.resources_table().get(*rid).unwrap(), *rid));
200+
// The resource id we stored can be invalid due to
201+
// the resource table getting modified by an external source
202+
// (e.g. `App::cleanup_before_exit` > `manager.resources_table.clear()`)
203+
return Ok((self.app.resources_table().get(*rid)?, *rid));
201204
}
202205

203206
// if stores.contains_key(&self.path) {

0 commit comments

Comments
 (0)