1use std::path::PathBuf;
2
3#[derive(thiserror::Error, Debug)]
5pub enum Error {
6 #[error("can't set local variable outside of function")]
8 SetLocalVarOutsideFunction,
9
10 #[error("cannot expand tilde expression with HOME not set")]
12 TildeWithoutValidHome,
13
14 #[error("cannot assign list to array member")]
16 AssigningListToArrayMember,
17
18 #[error("cannot convert associative array to indexed array")]
20 ConvertingAssociativeArrayToIndexedArray,
21
22 #[error("cannot convert indexed array to associative array")]
24 ConvertingIndexedArrayToAssociativeArray,
25
26 #[error("failed to source file: {0}; {1}")]
28 FailedSourcingFile(PathBuf, Box<Error>),
29
30 #[error("failed to send signal to process")]
32 FailedToSendSignal,
33
34 #[error("cannot assign in this way")]
36 CannotAssignToSpecialParameter,
37
38 #[error("expansion error: {0}")]
40 CheckedExpansionError(String),
41
42 #[error("function not found: {0}")]
44 FunctionNotFound(String),
45
46 #[error("command not found: {0}")]
48 CommandNotFound(String),
49
50 #[error("UNIMPLEMENTED: {0}")]
52 Unimplemented(&'static str),
53
54 #[error("missing scope")]
56 MissingScope,
57
58 #[error("not a directory: {0}")]
60 NotADirectory(PathBuf),
61
62 #[error("path is a directory")]
64 IsADirectory,
65
66 #[error("variable is not an array")]
68 NotArray,
69
70 #[error("no current user")]
72 NoCurrentUser,
73
74 #[error("invalid redirection")]
76 InvalidRedirection,
77
78 #[error("failed to redirect to {0}: {1}")]
80 RedirectionFailure(String, std::io::Error),
81
82 #[error("arithmetic evaluation error: {0}")]
84 EvalError(#[from] crate::arithmetic::EvalError),
85
86 #[error("failed to parse integer")]
88 IntParseError(#[from] std::num::ParseIntError),
89
90 #[error("failed to parse integer")]
92 TryIntParseError(#[from] std::num::TryFromIntError),
93
94 #[error("failed to decode utf-8")]
96 FromUtf8Error(#[from] std::string::FromUtf8Error),
97
98 #[error("failed to decode utf-8")]
100 Utf8Error(#[from] std::str::Utf8Error),
101
102 #[error("cannot mutate readonly variable")]
104 ReadonlyVariable,
105
106 #[error("invalid pattern: '{0}'")]
108 InvalidPattern(String),
109
110 #[error("regex error: {0}")]
112 RegexError(#[from] fancy_regex::Error),
113
114 #[error("invalid regex: {0}; expression: '{1}'")]
116 InvalidRegexError(fancy_regex::Error, String),
117
118 #[error("i/o error: {0}")]
120 IoError(#[from] std::io::Error),
121
122 #[error("bad substitution")]
124 BadSubstitution,
125
126 #[error("invalid arguments")]
128 InvalidArguments,
129
130 #[error("failed to create child process")]
132 ChildCreationFailure,
133
134 #[error("{0}")]
136 FormattingError(#[from] std::fmt::Error),
137
138 #[error("{0}")]
140 WordParseError(#[from] brush_parser::WordParseError),
141
142 #[error("{0}")]
144 TestCommandParseError(#[from] brush_parser::TestCommandParseError),
145
146 #[error("threading error")]
148 ThreadingError(#[from] tokio::task::JoinError),
149
150 #[error("{0}: invalid signal specification")]
152 InvalidSignal(String),
153
154 #[cfg(unix)]
156 #[error("system error: {0}")]
157 ErrnoError(#[from] nix::errno::Errno),
158
159 #[error("invalid umask value")]
161 InvalidUmask,
162
163 #[cfg(target_os = "linux")]
165 #[error("procfs error: {0}")]
166 ProcfsError(#[from] procfs::ProcError),
167
168 #[error("cannot read from {0}")]
170 OpenFileNotReadable(&'static str),
171
172 #[error("cannot write to {0}")]
174 OpenFileNotWritable(&'static str),
175
176 #[error("bad file descriptor: {0}")]
178 BadFileDescriptor(u32),
179
180 #[error("printf failure: {0}")]
182 PrintfFailure(i32),
183
184 #[error("interrupted")]
186 Interrupted,
187
188 #[error("maximum function call depth exceeded")]
190 MaxFunctionCallDepthExceeded,
191
192 #[error("system time error: {0}")]
194 TimeError(#[from] std::time::SystemTimeError),
195}
196
197pub(crate) fn unimp<T>(msg: &'static str) -> Result<T, Error> {
203 Err(Error::Unimplemented(msg))
204}