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("not yet implemented: {0}")]
52 Unimplemented(&'static str),
53
54 #[error("not yet implemented: {0}; see https://github.com/reubeno/brush/issues/{1}")]
57 UnimplementedAndTracked(&'static str, u32),
58
59 #[error("missing scope")]
61 MissingScope,
62
63 #[error("not a directory: {0}")]
65 NotADirectory(PathBuf),
66
67 #[error("path is a directory")]
69 IsADirectory,
70
71 #[error("variable is not an array")]
73 NotArray,
74
75 #[error("no current user")]
77 NoCurrentUser,
78
79 #[error("invalid redirection")]
81 InvalidRedirection,
82
83 #[error("failed to redirect to {0}: {1}")]
85 RedirectionFailure(String, std::io::Error),
86
87 #[error("arithmetic evaluation error: {0}")]
89 EvalError(#[from] crate::arithmetic::EvalError),
90
91 #[error("failed to parse integer")]
93 IntParseError(#[from] std::num::ParseIntError),
94
95 #[error("failed to parse integer")]
97 TryIntParseError(#[from] std::num::TryFromIntError),
98
99 #[error("failed to decode utf-8")]
101 FromUtf8Error(#[from] std::string::FromUtf8Error),
102
103 #[error("failed to decode utf-8")]
105 Utf8Error(#[from] std::str::Utf8Error),
106
107 #[error("cannot mutate readonly variable")]
109 ReadonlyVariable,
110
111 #[error("invalid pattern: '{0}'")]
113 InvalidPattern(String),
114
115 #[error("regex error: {0}")]
117 RegexError(#[from] fancy_regex::Error),
118
119 #[error("invalid regex: {0}; expression: '{1}'")]
121 InvalidRegexError(fancy_regex::Error, String),
122
123 #[error("i/o error: {0}")]
125 IoError(#[from] std::io::Error),
126
127 #[error("bad substitution")]
129 BadSubstitution,
130
131 #[error("invalid arguments")]
133 InvalidArguments,
134
135 #[error("failed to create child process")]
137 ChildCreationFailure,
138
139 #[error("{0}")]
141 FormattingError(#[from] std::fmt::Error),
142
143 #[error("{0}")]
145 ParseError(#[from] brush_parser::ParseError),
146
147 #[error("{0}")]
149 WordParseError(#[from] brush_parser::WordParseError),
150
151 #[error("{0}")]
153 TestCommandParseError(#[from] brush_parser::TestCommandParseError),
154
155 #[error("{0}")]
157 BindingParseError(#[from] brush_parser::BindingParseError),
158
159 #[error("threading error")]
161 ThreadingError(#[from] tokio::task::JoinError),
162
163 #[error("{0}: invalid signal specification")]
165 InvalidSignal(String),
166
167 #[cfg(unix)]
169 #[error("system error: {0}")]
170 ErrnoError(#[from] nix::errno::Errno),
171
172 #[error("invalid umask value")]
174 InvalidUmask,
175
176 #[cfg(target_os = "linux")]
178 #[error("procfs error: {0}")]
179 ProcfsError(#[from] procfs::ProcError),
180
181 #[error("cannot read from {0}")]
183 OpenFileNotReadable(&'static str),
184
185 #[error("cannot write to {0}")]
187 OpenFileNotWritable(&'static str),
188
189 #[error("bad file descriptor: {0}")]
191 BadFileDescriptor(u32),
192
193 #[error("printf failure: {0}")]
195 PrintfFailure(i32),
196
197 #[error("printf: {0}")]
199 PrintfInvalidUsage(String),
200
201 #[error("interrupted")]
203 Interrupted,
204
205 #[error("maximum function call depth exceeded")]
207 MaxFunctionCallDepthExceeded,
208
209 #[error("system time error: {0}")]
211 TimeError(#[from] std::time::SystemTimeError),
212
213 #[error("array index out of range")]
215 ArrayIndexOutOfRange,
216
217 #[error("unhandled key code: {0:?}")]
219 UnhandledKeyCode(Vec<u8>),
220}
221
222pub(crate) const fn unimp<T>(msg: &'static str) -> Result<T, Error> {
228 Err(Error::Unimplemented(msg))
229}
230
231pub(crate) const fn unimp_with_issue<T>(
237 msg: &'static str,
238 project_issue_id: u32,
239) -> Result<T, Error> {
240 Err(Error::UnimplementedAndTracked(msg, project_issue_id))
241}