Skip to main content

oxios_kernel/pty/
error.rs

1//! Error type for PTY subsystem (RFC-038).
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum PtyError {
6    /// Master switch disabled in config.
7    #[error("pty subsystem is disabled in config")]
8    Disabled,
9
10    /// Per-principal session cap reached.
11    #[error("session cap reached for principal: max {max}")]
12    SessionCapReached { max: u32 },
13
14    /// Requested shell binary is not in `allowed_shells` allowlist.
15    #[error("shell not allowed: {shell:?}")]
16    ShellNotAllowed { shell: String },
17
18    /// Spawning the PTY child process failed.
19    #[error("failed to spawn pty: {0}")]
20    Spawn(String),
21
22    /// Resize / write / close on an unknown session.
23    #[error("session not found: {0}")]
24    NotFound(String),
25
26    /// Resize / write on a closed session.
27    #[error("session {0} is closed")]
28    Closed(String),
29
30    /// Resize / write on a session owned by another principal.
31    #[error("session {0} not owned by caller")]
32    NotOwner(String),
33
34    /// Master/slave I/O error.
35    #[error("pty io: {0}")]
36    Io(String),
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn display_messages() {
45        assert_eq!(
46            PtyError::Disabled.to_string(),
47            "pty subsystem is disabled in config"
48        );
49        assert_eq!(
50            PtyError::SessionCapReached { max: 3 }.to_string(),
51            "session cap reached for principal: max 3"
52        );
53        assert_eq!(
54            PtyError::ShellNotAllowed {
55                shell: "fish".into()
56            }
57            .to_string(),
58            "shell not allowed: \"fish\""
59        );
60    }
61}