1#![deny(unused_crate_dependencies)]
2
3use thiserror::Error;
4
5#[allow(missing_docs, dead_code)]
6#[derive(Error, Debug)]
7pub enum Error {
8 #[error("Unknown Error")]
9 Unknown,
10
11 #[error("Not Implemented")]
12 NotImplemented,
13
14 #[error("Cannot start a new transaction")]
15 CannotStartNewTransaction,
16
17 #[error("Invalid Input")]
18 InvalidInput,
19
20 #[error("No Input Records")]
21 NoInputRecords,
22
23 #[error("Timeout")]
24 Timeout,
25
26 #[error("Mandatory Environment Variable {0} is empty")]
27 EnvironmentVariableEmpty(String),
28
29 #[error("Mandatory Environment Variable {0} missing")]
30 MandatoryEnvironmentVariableMissing(String),
31
32 #[error("Mandatory Environment Variable {0} is not a valid IRI")]
33 MandatoryEnvironmentVariableIsNotIRI(String),
34
35 #[error("Service error {0}")]
36 ServiceError(String),
37
38 #[error("No event")]
39 NoEvent,
40
41 #[error("No subject")]
42 NoSubject,
43
44 #[error("No predicate")]
45 NoPredicate,
46
47 #[error("Path {0} does not exist")]
48 PathDoesNotExist(String),
49
50 #[error("No root project found")]
51 NoRootProjectFound,
52
53 #[error(
54 "Detected an unknown story input parameter [{param}] for story [{story_key}], expected \
55 parameters are: {expected_params:?}"
56 )]
57 DetectedUnknownStoryInputParameter {
58 story_key: String,
59 param: String,
60 expected_params: Vec<String>,
61 },
62
63 #[error("No base IRI specified")]
64 NoBaseIRISpecified,
65
66 #[error("No identifier namespace specified")]
67 NoIdentifierNamespaceSpecified,
68
69 #[error("Incorrect base IRI: {iri}")]
70 IncorrectBaseIRI { iri: String },
71
72 #[error("The A-box namespace IRI {iri} does not end with a slash")]
73 ABoxNamespaceIRIDoesNotEndWithSlash { iri: String },
74
75 #[error("Parse Error")]
76 Parse,
77
78 #[cfg(feature = "uuid")]
79 #[error(transparent)]
80 UuidParseError(#[from] uuid::Error),
81
82 #[error("Could not fetch context and objects")]
83 MissingContext,
84
85 #[error("Could not generate metadata")]
86 CouldNotGenerateMetadata,
87
88 #[error("Could not find root project")]
89 CouldNotFindRootProject,
90
91 #[error("Could not rewrite IRI [{iri}]")]
92 CouldNotRewriteIRI { iri: String },
93
94 #[error("Invalid Docker Image ID")]
95 InvalidDockerImageId,
96
97 #[error("Could not lock a resource: {msg}")]
98 CouldNotLock { msg: String },
99
100 #[error("Missing Identifier Base IRI")]
101 MissingIdentifierBaseIRI,
102
103 #[error("Could not create the story service client")]
104 CouldNotCreateClient,
105
106 #[error("Could not connect to the database server")]
107 CouldNotConnectToServer,
108
109 #[error("There's no context")]
110 NoContextProvided,
111
112 #[error("Invalid Story Service IRI")]
113 InvalidClientIri,
114
115 #[error("Persona {persona_key} does not exist")]
116 PersonaDoesNotExist { persona_key: String },
117
118 #[error("Story {use_case_key}/{story_key} does not exist")]
119 StoryDoesNotExist { story_key: String, use_case_key: String },
120
121 #[error("Could not find story implementation {implementation_file} for story {story_id}")]
122 CouldNotFindStory {
123 implementation_file: String,
124 story_id: String,
125 },
126
127 #[error("Could not find use case {0}")]
128 CouldNotFindUseCase(String),
129
130 #[error("UseCase {use_case_key} does not exist")]
131 UseCaseDoesNotExist { use_case_key: String },
132
133 #[cfg(feature = "serde")]
134 #[error("JSON Parsing Error")]
135 JSONParseError(serde_path_to_error::Error<serde_json::Error>),
136
137 #[cfg(feature = "serde")]
138 #[error(transparent)]
139 SerdeJsonError(#[from] serde_json::Error),
140
141 #[error("Invalid Story IRI")]
142 InvalidStoryIri,
143
144 #[error("Could not get story results")]
145 CouldNotGetStoryResults,
146
147 #[error(transparent)]
149 IOError(#[from] std::io::Error),
150
151 #[error(transparent)]
152 ParseIntError(#[from] std::num::ParseIntError),
153
154 #[cfg(all(feature = "sparql", not(target_arch = "wasm32")))]
156 #[error("Encountered SPARQL error \"{source:}\" in\n{statement:}")]
157 SPARQLStatementError {
158 #[source]
159 source: spargebra::ParseError,
160 statement: String,
161 },
162
163 #[error(transparent)]
164 FormatError(#[from] core::fmt::Error),
165
166 #[cfg(feature = "fs")]
169 #[error(transparent)]
170 WalkError(#[from] ignore::Error),
171
172 #[cfg(feature = "iref")]
173 #[error(transparent)]
174 IriErrorString(#[from] iref::IriError<String>),
175
176 #[error(transparent)]
177 IriStringParseError(#[from] iri_string::validate::Error),
178
179 #[error(transparent)]
180 IriStringCreationError(#[from] iri_string::types::CreationError<String>),
181
182 #[error(transparent)]
183 CApiError(#[from] std::ffi::NulError),
184
185 #[cfg(all(feature = "rdftk-support", not(target_arch = "wasm32")))]
186 #[error(transparent)]
187 RDFTkError(#[from] rdftk_core::error::Error),
188
189 #[cfg(all(feature = "rdftk-support", not(target_arch = "wasm32")))]
190 #[error(transparent)]
191 RDFTkIRIError(#[from] rdftk_iri::error::Error),
192
193 #[error("Could not open database: {source:}")]
194 CouldNotOpenDatabase { source: Box<Error> },
195
196 #[cfg(all(not(target_arch = "wasm32"), feature = "xlsx"))]
197 #[error(transparent)]
198 ExcelWriterError(#[from] xlsxwriter::XlsxError),
199
200 #[cfg(all(
201 not(target_arch = "wasm32"),
202 feature = "no-wasm",
203 feature = "color-eyre"
204 ))]
205 #[error(transparent)]
206 ColorEyreError(#[from] color_eyre::eyre::ErrReport),
207
208 #[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
209 #[error(transparent)]
210 InvalidHeaderValue(#[from] salvo::http::header::InvalidHeaderValue),
211
212 #[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
213 #[error(transparent)]
214 SalvoError(#[from] salvo::Error),
215
216 #[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
217 #[error(transparent)]
218 ToStrError(#[from] salvo_core::http::header::ToStrError),
219
220 #[cfg(feature = "tokio")]
221 #[error(transparent)]
222 TokioJoinError(#[from] tokio::task::JoinError),
223
224 #[cfg(feature = "tauri")]
225 #[error(transparent)]
226 TauriError(#[from] tauri::Error),
227
228 #[cfg(feature = "gix")]
229 #[error(transparent)]
230 GitDiscoverUpwardsError2(#[from] gix_discover::upwards::Error),
231
232 #[cfg(feature = "reqwest")]
233 #[error(transparent)]
234 ReqwestError(#[from] reqwest::Error),
235
236 #[cfg(feature = "reqwest")]
237 #[error(transparent)]
238 UrlParseError(#[from] url::ParseError),
239
240 #[cfg(all(feature = "reqwest", not(target_arch = "wasm32")))]
241 #[error(transparent)]
242 StreamBodyError(#[from] reqwest_streams::error::StreamBodyError),
243
244 #[cfg(feature = "iri-string")]
245 #[error(transparent)]
246 IriStringCreationError(#[from] iri_string::types::CreationError<String>),
247
248 #[cfg(feature = "iri")]
249 #[error("Encountered IRI error \"{error:}\" in\n{iri:}")]
250 IrefError { error: ekg_error::Error, iri: String },
251
252 #[cfg(feature = "aws-lambda")]
253 #[error(transparent)]
254 LambdaError(#[from] lambda_runtime::Error),
255
256 #[cfg(feature = "aws-lambda")]
257 #[error(transparent)]
258 InvalidAppName(#[from] aws_types::app_name::InvalidAppName),
259
260 #[cfg(not(target_arch = "wasm32"))]
261 #[error(transparent)]
262 HyperError(#[from] hyper::Error),
263
264 #[cfg(not(target_arch = "wasm32"))]
265 #[error(transparent)]
266 HttpError(#[from] hyper::http::Error),
267
268 #[cfg(not(target_arch = "wasm32"))]
269 #[error(transparent)]
270 InvalidUri(#[from] hyper::http::uri::InvalidUri),
271
272 #[error("Invalid IRI: {0}")]
273 InvalidIri(String),
274
275 #[error("Invalid base IRI: {0}")]
276 InvalidBaseIri(String),
277
278 #[error(transparent)]
279 SerdeUrlEncodingError(#[from] serde_urlencoded::ser::Error),
280
281 #[error("Unknown data type {data_type_id}")]
282 UnknownDataType { data_type_id: u8 },
283 #[error("Unknown value [{value}] for data type {data_type_xsd_iri:?}")]
284 UnknownValueForDataType {
285 data_type_xsd_iri: String,
286 value: String,
287 },
288 #[error("Unknown XSD data type {data_type_iri}")]
289 UnknownXsdDataType { data_type_iri: String },
290 #[error("Unknown literal value in N-Triples format: {value}")]
291 UnknownNTriplesValue { value: String },
292
293 #[cfg(feature = "tracing-subscriber")]
294 #[error(transparent)]
295 EnvFilterParseError(#[from] tracing_subscriber::filter::ParseError),
296
297 #[cfg(feature = "tracing-subscriber")]
298 #[error(transparent)]
299 TracingSubscriberError(#[from] tracing::subscriber::SetGlobalDefaultError),
300
301 #[cfg(feature = "tracing-subscriber")]
302 #[error(transparent)]
303 TracingSubscriberTryInitError(#[from] tracing_subscriber::util::TryInitError),
304
305 #[cfg(feature = "tracing-subscriber")]
306 #[error(transparent)]
307 FromEnvError(#[from] tracing_subscriber::filter::FromEnvError),
308
309 #[cfg(all(feature = "rdfox-support", not(target_arch = "wasm32")))]
310 #[error(transparent)]
311 R2D2Error(#[from] r2d2::Error),
312
313 #[error("While {action}: {message}")]
314 Exception { action: String, message: String },
315 #[error(
316 "The multiplicity ({multiplicity}) of a cursor row exceeded the maximum number of rows \
317 ({maxrow}) for query:\n{query}"
318 )]
319 MultiplicityExceededMaximumNumberOfRows {
320 maxrow: usize,
321 multiplicity: usize,
322 query: String,
323 },
324 #[error("Cannot get any argument indexes from the cursor of:\n{query}")]
325 CannotGetAnyArgumentIndexes { query: String },
326 #[error("Maximum number of rows ({maxrow}) has been exceeded for query:\n{query}")]
327 ExceededMaximumNumberOfRows { maxrow: usize, query: String },
328 #[error("Could not find a license key")]
329 RDFoxLicenseFileNotFound,
330 #[error("Unknown resource")]
331 UnknownResourceException,
332 #[error("Could not create RDFox server")]
333 CouldNotCreateRDFoxServer,
334 #[error("Could not import RDF File")]
335 CouldNotImportRDFFile,
336 #[error("Invalid prefix name")]
337 InvalidPrefixName,
338 #[error("Invalid literal value")]
339 InvalidLiteral,
340 #[error("Could not parse IRI: {0:?}")]
341 IriParseError(String),
342
343 #[cfg(not(target_arch = "wasm32"))]
344 #[error(transparent)]
345 DateParseError(#[from] chrono::ParseError),
346
347 #[cfg(all(feature = "rdfox-support", not(target_arch = "wasm32")))]
348 #[error(transparent)]
349 RDFoxError(#[from] rdfox_sys::Error),
350
351 #[error(transparent)]
352 FromPathError(#[from] relative_path::FromPathError),
353
354 #[error(transparent)]
355 StripPrefixError(#[from] std::path::StripPrefixError),
356}
357
358unsafe impl Send for Error {}
359
360#[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
361#[salvo::async_trait]
362impl salvo::Writer for Error {
363 async fn write(
364 mut self,
365 _req: &mut salvo::http::Request,
366 _depot: &mut salvo::Depot,
367 res: &mut salvo::http::Response,
368 ) {
369 res.status_code(salvo::http::StatusCode::INTERNAL_SERVER_ERROR);
370 res.render("custom error");
371 }
372}
373
374impl From<iref::InvalidIri<String>> for Error {
375 fn from(value: iref::InvalidIri<String>) -> Self { Error::InvalidIri(value.to_string()) }
376}
377
378impl From<iref::InvalidIri<&str>> for Error {
379 fn from(value: iref::InvalidIri<&str>) -> Self { Error::InvalidIri(value.to_string()) }
380}
381
382#[cfg(not(target_arch = "wasm32"))]
383impl<I: From<&'static str>> From<Error> for nom::Err<nom::error::Error<I>> {
384 fn from(_: Error) -> Self {
385 nom::Err::Error(nom::error::Error::new(
386 "unknown datastore error".into(),
387 nom::error::ErrorKind::Fail,
388 ))
389 }
390}