1use std::io;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum NdsError {
6 #[error("IO error: {0}")]
7 Io(#[from] io::Error),
8
9 #[error("Session not found: {0}")]
10 SessionNotFound(String),
11
12 #[error("Session already exists: {0}")]
13 SessionAlreadyExists(String),
14
15 #[error("PTY error: {0}")]
16 PtyError(String),
17
18 #[error("Fork error: {0}")]
19 ForkError(String),
20
21 #[error("Socket error: {0}")]
22 SocketError(String),
23
24 #[error("JSON serialization error: {0}")]
25 SerializationError(#[from] serde_json::Error),
26
27 #[error("Permission denied: {0}")]
28 PermissionDenied(String),
29
30 #[error("Invalid session ID: {0}")]
31 InvalidSessionId(String),
32
33 #[error("Session is already attached")]
34 SessionAlreadyAttached,
35
36 #[error("Failed to create session directory: {0}")]
37 DirectoryCreationError(String),
38
39 #[error("Signal error: {0}")]
40 SignalError(String),
41
42 #[error("Terminal error: {0}")]
43 TerminalError(String),
44
45 #[error("Process error: {0}")]
46 ProcessError(String),
47}
48
49pub type Result<T> = std::result::Result<T, NdsError>;
50
51impl From<nix::Error> for NdsError {
52 fn from(err: nix::Error) -> Self {
53 match err {
54 nix::Error::EPERM => NdsError::PermissionDenied(err.to_string()),
55 _ => NdsError::PtyError(err.to_string()),
56 }
57 }
58}