summaryrefslogtreecommitdiffstats
path: root/zellij-server
diff options
context:
space:
mode:
authorhar7an <99636919+har7an@users.noreply.github.com>2023-01-19 18:17:33 +0000
committerGitHub <noreply@github.com>2023-01-19 18:17:33 +0000
commitb274fc5ab19abe8b3ef7f7afe38897f526263414 (patch)
treebaf1ae9cc8407da95558ad827d63d6de5c964979 /zellij-server
parent670b9c27597c656cd457be8a41e6548d007b4feb (diff)
errors: handle missing plugin caches (#2093)
* server/plugins: Always recreate plugin folders in case they aren't existent and don't mark errors to do so as non-fatal. The latter masks the underlying cause when e.g. the `.cache` folder is, for some reason, not writable by zellij (See #2092), whereas the former fixes problems arising from the user having purged their .cache/zellij folder entirely. * utils/errors: Rewrite panic message * changelog: Add PR #2093
Diffstat (limited to 'zellij-server')
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs
index abb405ba1..6271295e7 100644
--- a/zellij-server/src/plugins/wasm_bridge.rs
+++ b/zellij-server/src/plugins/wasm_bridge.rs
@@ -247,6 +247,15 @@ impl WasmBridge {
let plugin_own_data_dir = ZELLIJ_CACHE_DIR.join(Url::from(&plugin.location).to_string());
let cache_hit = self.plugin_cache.contains_key(&plugin.path);
+ // Create filesystem entries mounted into WASM.
+ // We create them here to get expressive error messages in case they fail.
+ fs::create_dir_all(&plugin_own_data_dir)
+ .with_context(|| format!("failed to create datadir in {plugin_own_data_dir:?}"))
+ .with_context(err_context)?;
+ fs::create_dir_all(ZELLIJ_TMP_DIR.as_path())
+ .with_context(|| format!("failed to create tmpdir at {:?}", &ZELLIJ_TMP_DIR.as_path()))
+ .with_context(err_context)?;
+
// We remove the entry here and repopulate it at the very bottom, if everything went well.
// We must do that because a `get` will only give us a borrow of the Module. This suffices for
// the purpose of setting everything up, but we cannot return a &Module from the "None" match
@@ -277,19 +286,6 @@ impl WasmBridge {
.with_context(err_context)
.fatal();
- fs::create_dir_all(&plugin_own_data_dir)
- .with_context(|| format!("failed to create datadir in {plugin_own_data_dir:?}"))
- .with_context(err_context)
- .non_fatal();
-
- // ensure tmp dir exists, in case it somehow was deleted (e.g systemd-tmpfiles)
- fs::create_dir_all(ZELLIJ_TMP_DIR.as_path())
- .with_context(|| {
- format!("failed to create tmpdir at {:?}", &ZELLIJ_TMP_DIR.as_path())
- })
- .with_context(err_context)
- .non_fatal();
-
let hash: String = PortableHash::default()
.hash256(&wasm_bytes)
.iter()
@@ -310,16 +306,17 @@ impl WasmBridge {
Err(e) => {
let inner_context = || format!("failed to recover from {e:?}");
- let m = Module::new(&self.store, &wasm_bytes)
- .with_context(inner_context)
- .with_context(err_context)?;
fs::create_dir_all(ZELLIJ_CACHE_DIR.to_owned())
+ .map_err(anyError::new)
+ .and_then(|_| {
+ Module::new(&self.store, &wasm_bytes).map_err(anyError::new)
+ })
+ .and_then(|m| {
+ m.serialize_to_file(&cached_path).map_err(anyError::new)?;
+ Ok(m)
+ })
.with_context(inner_context)
- .with_context(err_context)?;
- m.serialize_to_file(&cached_path)
- .with_context(inner_context)
- .with_context(err_context)?;
- m
+ .with_context(err_context)?
},
}
}