Skip to main content

mlua_isle/
error.rs

1//! Error types for mlua-isle.
2
3/// Errors returned by Isle operations.
4#[derive(Debug, PartialEq, thiserror::Error)]
5pub enum IsleError {
6    /// The Lua VM thread has already shut down.
7    #[error("isle shut down")]
8    Shutdown,
9
10    /// The operation was cancelled via [`CancelToken`](crate::CancelToken).
11    #[error("cancelled")]
12    Cancelled,
13
14    /// A Lua runtime error.
15    #[error("lua error: {0}")]
16    Lua(String),
17
18    /// The Lua thread panicked.
19    #[error("lua thread panicked")]
20    ThreadPanic,
21
22    /// Failed to send request to the Lua thread.
23    #[error("send failed (isle shut down)")]
24    SendFailed,
25
26    /// Failed to receive response from the Lua thread.
27    #[error("recv failed: {0}")]
28    RecvFailed(String),
29
30    /// Error during Isle initialization.
31    #[error("init error: {0}")]
32    Init(String),
33}
34
35impl From<mlua::Error> for IsleError {
36    fn from(e: mlua::Error) -> Self {
37        let msg = e.to_string();
38        if msg.contains("__isle_cancelled__") {
39            Self::Cancelled
40        } else {
41            Self::Lua(msg)
42        }
43    }
44}