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)]
5#[non_exhaustive]
6pub enum IsleError {
7    /// The Lua VM thread has already shut down.
8    #[error("isle shut down")]
9    Shutdown,
10
11    /// The operation was cancelled via [`CancelToken`](crate::CancelToken).
12    #[error("cancelled")]
13    Cancelled,
14
15    /// A Lua runtime error.
16    #[error("lua error: {0}")]
17    Lua(String),
18
19    /// The Lua thread panicked.
20    #[error("lua thread panicked")]
21    ThreadPanic,
22
23    /// The request channel is full (backpressure).
24    ///
25    /// Only returned by [`AsyncIsle`](crate::AsyncIsle) `spawn_*` methods
26    /// when the bounded channel has no capacity.  Unlike [`Shutdown`](Self::Shutdown),
27    /// this is a transient condition — the Lua thread is still alive and
28    /// retrying may succeed.
29    #[cfg(feature = "tokio")]
30    #[error("channel full (backpressure)")]
31    ChannelFull,
32
33    /// Failed to receive response from the Lua thread.
34    ///
35    /// The oneshot / mpsc response channel was dropped before a result
36    /// was sent.  This typically means the Lua thread panicked or was
37    /// shut down while a request was in flight.
38    #[error("recv failed: {0}")]
39    RecvFailed(String),
40
41    /// Error during Isle initialization.
42    #[error("init error: {0}")]
43    Init(String),
44}
45
46impl From<mlua::Error> for IsleError {
47    fn from(e: mlua::Error) -> Self {
48        let msg = e.to_string();
49        if msg.contains("__isle_cancelled__") {
50            Self::Cancelled
51        } else {
52            Self::Lua(msg)
53        }
54    }
55}