mlua_probe_core/debug/error.rs
1//! Error types for the debug engine.
2//!
3//! [`DebugError`] is the public error type for [`DebugController`] and
4//! [`DebugSession`] APIs. It deliberately does **not** expose
5//! [`mlua::Error`] — frontends should remain independent of the Lua
6//! binding layer.
7//!
8//! Hook-internal errors use [`mlua::Error`] instead (see
9//! [`engine`](super::engine) module docs for the two-path rationale).
10//!
11//! [`DebugController`]: super::controller::DebugController
12//! [`DebugSession`]: super::engine::DebugSession
13
14use thiserror::Error;
15
16/// Errors returned by [`DebugController`](super::controller::DebugController)
17/// and [`DebugSession`](super::engine::DebugSession) methods.
18#[derive(Debug, Error)]
19pub enum DebugError {
20 /// The debug session has been closed (channel disconnected).
21 #[error("debug session closed: {0}")]
22 SessionClosed(String),
23 /// The command is not valid in the current session state.
24 #[error("invalid state: {0}")]
25 InvalidState(String),
26 /// Expression evaluation failed.
27 #[error("eval error: {0}")]
28 EvalError(String),
29 /// An internal error (e.g. mutex poisoned). Indicates a bug or
30 /// a panic on another thread — the session is no longer usable.
31 #[error("internal error: {0}")]
32 Internal(String),
33}
34
35impl<T> From<std::sync::mpsc::SendError<T>> for DebugError {
36 fn from(_: std::sync::mpsc::SendError<T>) -> Self {
37 Self::SessionClosed("command send failed: engine disconnected".into())
38 }
39}
40
41impl From<std::sync::mpsc::RecvError> for DebugError {
42 fn from(_: std::sync::mpsc::RecvError) -> Self {
43 Self::SessionClosed("event receive failed: engine disconnected".into())
44 }
45}
46
47/// A poisoned mutex means another thread panicked while holding the
48/// lock. The session is unrecoverable — map to [`DebugError::Internal`].
49impl<T> From<std::sync::PoisonError<T>> for DebugError {
50 fn from(e: std::sync::PoisonError<T>) -> Self {
51 Self::Internal(format!("mutex poisoned: {e}"))
52 }
53}