Skip to content

Commit 469732a

Browse files
committed
feat: added proper error handling to hsr
1 parent ec52b1c commit 469732a

File tree

1 file changed

+5
-17
lines changed
  • packages/perseus/src/state

1 file changed

+5
-17
lines changed

packages/perseus/src/state/hsr.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,34 @@ use crate::templates::RenderCtx;
33
use wasm_bindgen::JsValue;
44

55
/// Freezes the app's state to IndexedDB to be accessed in future.
6-
// TODO Error handling
76
pub async fn hsr_freeze(render_ctx: RenderCtx) {
87
let frozen_state = render_ctx.freeze();
98
// We use a custom name so we don't interfere with any state freezing the user's doing independently
109
let idb_store = match IdbFrozenStateStore::new_with_name("perseus_hsr").await {
1110
Ok(idb_store) => idb_store,
12-
Err(_) => {
13-
return;
14-
}
11+
Err(err) => return log(&format!("IndexedDB setup error: {}.", err)),
1512
};
1613
match idb_store.set(&frozen_state).await {
1714
Ok(_) => log("State frozen."),
18-
Err(_) => {
19-
return;
20-
}
15+
Err(err) => log(&format!("State freezing error: {}.", err)),
2116
};
2217
}
2318

2419
/// Thaws a previous state frozen in development.
2520
// This will be run at the beginning of every template function, which means it gets executed on the server as well, so we have to Wasm-gate this
2621
#[cfg(target_arch = "wasm32")]
27-
// TODO Error handling
2822
pub async fn hsr_thaw(render_ctx: RenderCtx) {
2923
use super::{PageThawPrefs, ThawPrefs};
3024

3125
let idb_store = match IdbFrozenStateStore::new_with_name("perseus_hsr").await {
3226
Ok(idb_store) => idb_store,
33-
Err(_) => {
34-
return;
35-
}
27+
Err(err) => return log(&format!("IndexedDB setup error: {}.", err)),
3628
};
3729
let frozen_state = match idb_store.get().await {
3830
Ok(Some(frozen_state)) => frozen_state,
3931
// If there's no frozen state available, we'll proceed as usual
4032
Ok(None) => return,
41-
Err(_) => {
42-
return;
43-
}
33+
Err(err) => return log(&format!("Frozen state acquisition error: {}.", err)),
4434
};
4535

4636
// This is designed to override everything to restore the app to its previous state, so we should override everything
@@ -61,9 +51,7 @@ pub async fn hsr_thaw(render_ctx: RenderCtx) {
6151
// We don't want this old state to persist if the user manually reloads (they'd be greeted with state that's probably out-of-date)
6252
match idb_store.clear().await {
6353
Ok(_) => (),
64-
Err(_) => {
65-
return;
66-
}
54+
Err(err) => log(&format!("Stale state clearing error: {}.", err)),
6755
}
6856
}
6957

0 commit comments

Comments
 (0)