diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-10-20 15:49:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 15:49:04 +0000 |
commit | a56723f7ce58b88e9b132115664571293d7a0ea6 (patch) | |
tree | b0e5b46fc414615b169c504b14131ba71acc04a8 /zellij-utils | |
parent | b94a626959530c30600b807af11e32e3e525241b (diff) |
errors: Don't panic in `wasm_vm` (#1827)
* server/wasm_vm: Compact module imports
* utils/errors: Impl `to_anyhow` for PoisonError
which is returned by calls to `lock` on various types of locks from
`std`. In our case, some of the locks we try to acquire in `wasm_vm` can
contain an `mpsc::Sender`, which is `!Send` and hence doesn't work with
`anyhow`. Turn the `PoisonError` into an error string instead and
returns that as `anyhow::Err`.
* wasm_vm: Remove calls to `unwrap`
in the WASM VM codes server API. Note that this doesn't include the
Plugin APIs. Mark the error as `fatal` in `server/lib`, where the wasm
thread is created.
This will cause zellij to report a proper error (and log it) when any of
the plugin-related functions fails. Unfortunately, this closes the
channel to the WASM thread. Hence, when loading the plugins upon startup
fails, the error reported in the terminal (visible to the user) hints
towards a call in `plugin_pane` being the culprit. However, the real
error will be contained in the logs.
Also add an error message and print it to the user in case that the
plugin failure was caused by a plugin version mismatch.
* server/wasm_vm: Restore panic on failure to load
plugins.
* server/wasm_vm: Add fix to plugin mismatch error
* server/panes/plugin_pane: Hint to logs
when failing to receive a message from the plugins for rendering pane
contents.
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/src/errors.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index a662ed246..0f7db131c 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -560,4 +560,21 @@ mod not_wasm { } } } + + impl<U> ToAnyhow<U> for Result<U, std::sync::PoisonError<U>> { + fn to_anyhow(self) -> crate::anyhow::Result<U> { + match self { + Ok(val) => crate::anyhow::Ok(val), + Err(e) => { + if *crate::consts::DEBUG_MODE.get().unwrap_or(&true) { + Err(crate::anyhow::anyhow!( + "cannot acquire poisoned lock for {e:#?}" + )) + } else { + Err(crate::anyhow::anyhow!("cannot acquire poisoned lock")) + } + }, + } + } + } } |