1use std::error::Error;
2use std::fmt::{self, Display};
3
4#[derive(Debug)]
5pub enum AllocateError {
6 Open(std::io::Error),
7 Grant(std::io::Error),
8 Unlock(std::io::Error),
9 GetChildName(std::io::Error),
10 OpenChild(std::io::Error),
11}
12
13#[derive(Debug)]
14pub enum SpawnError {
15 DuplicateStdio(std::io::Error),
16 CreateSession(std::io::Error),
17 SetControllingTerminal(std::io::Error),
18 Spawn(std::io::Error),
19 WrapAsyncFd(std::io::Error),
20}
21
22#[derive(Debug)]
23pub struct ResizeError(pub std::io::Error);
24
25impl Error for AllocateError {}
26impl Error for SpawnError {}
27impl Error for ResizeError {}
28
29impl Display for AllocateError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 AllocateError::Open(err) => write!(f, "failed to open new pseudo terminal: {err}"),
33 AllocateError::Grant(err) => write!(
34 f,
35 "failed to grant permissions on child terminal device: {err}"
36 ),
37 AllocateError::Unlock(err) => {
38 write!(f, "failed to unlock child terminal device: {err}")
39 }
40 AllocateError::GetChildName(err) => {
41 write!(f, "failed to get name of child terminal device: {err}")
42 }
43 AllocateError::OpenChild(err) => {
44 write!(f, "failed to open child terminal device: {err}")
45 }
46 }
47 }
48}
49
50impl Display for SpawnError {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match self {
53 SpawnError::DuplicateStdio(err) => write!(
54 f,
55 "failed to duplicate file descriptor for standard I/O stream: {err}"
56 ),
57 SpawnError::CreateSession(err) => {
58 write!(f, "failed to create new process group: {err}")
59 }
60 SpawnError::SetControllingTerminal(err) => write!(
61 f,
62 "failed to set controlling terminal for new process group: {err}"
63 ),
64 SpawnError::Spawn(err) => write!(f, "failed to spawn child process: {err}"),
65 SpawnError::WrapAsyncFd(err) => write!(
66 f,
67 "failed to wrap pseudo terminal file descriptor for use with tokio: {err}"
68 ),
69 }
70 }
71}
72
73impl Display for ResizeError {
74 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
75 let Self(e) = self;
76 write!(f, "failed to resize terminal device: {e}")
77 }
78}