use thiserror::Error;
#[derive(Debug, Error)]
pub enum PtyError {
#[error("pty subsystem is disabled in config")]
Disabled,
#[error("session cap reached for principal: max {max}")]
SessionCapReached { max: u32 },
#[error("shell not allowed: {shell:?}")]
ShellNotAllowed { shell: String },
#[error("failed to spawn pty: {0}")]
Spawn(String),
#[error("session not found: {0}")]
NotFound(String),
#[error("session {0} is closed")]
Closed(String),
#[error("session {0} not owned by caller")]
NotOwner(String),
#[error("pty io: {0}")]
Io(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_messages() {
assert_eq!(
PtyError::Disabled.to_string(),
"pty subsystem is disabled in config"
);
assert_eq!(
PtyError::SessionCapReached { max: 3 }.to_string(),
"session cap reached for principal: max 3"
);
assert_eq!(
PtyError::ShellNotAllowed {
shell: "fish".into()
}
.to_string(),
"shell not allowed: \"fish\""
);
}
}