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::SparqlSyntaxError,
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(feature = "salvo", not(target_arch = "wasm32")))]
201 #[error(transparent)]
202 InvalidHeaderValue(#[from] salvo::http::header::InvalidHeaderValue),
203
204 #[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
205 #[error(transparent)]
206 SalvoError(#[from] salvo::Error),
207
208 #[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
209 #[error(transparent)]
210 ToStrError(#[from] salvo_core::http::header::ToStrError),
211
212 #[cfg(feature = "tokio")]
213 #[error(transparent)]
214 TokioJoinError(#[from] tokio::task::JoinError),
215
216 #[cfg(feature = "tauri")]
217 #[error(transparent)]
218 TauriError(#[from] tauri::Error),
219
220 #[cfg(feature = "gix")]
221 #[error(transparent)]
222 GitDiscoverUpwardsError2(#[from] gix_discover::upwards::Error),
223
224 #[cfg(feature = "reqwest")]
225 #[error(transparent)]
226 ReqwestError(#[from] reqwest::Error),
227
228 #[cfg(feature = "reqwest")]
229 #[error(transparent)]
230 UrlParseError(#[from] url::ParseError),
231
232 #[cfg(all(feature = "reqwest", not(target_arch = "wasm32")))]
233 #[error(transparent)]
234 StreamBodyError(#[from] reqwest_streams::error::StreamBodyError),
235
236 #[cfg(feature = "aws-lambda")]
237 #[error(transparent)]
238 LambdaError(#[from] lambda_runtime::Error),
239
240 #[cfg(feature = "aws-lambda")]
241 #[error(transparent)]
242 InvalidAppName(#[from] aws_types::app_name::InvalidAppName),
243
244 #[cfg(not(target_arch = "wasm32"))]
245 #[error(transparent)]
246 HyperError(#[from] hyper::Error),
247
248 #[cfg(not(target_arch = "wasm32"))]
249 #[error(transparent)]
250 HttpError(#[from] hyper::http::Error),
251
252 #[cfg(not(target_arch = "wasm32"))]
253 #[error(transparent)]
254 InvalidUri(#[from] hyper::http::uri::InvalidUri),
255
256 #[error("Invalid IRI: {0}")]
257 InvalidIri(String),
258
259 #[error("Invalid base IRI: {0}")]
260 InvalidBaseIri(String),
261
262 #[error(transparent)]
263 SerdeUrlEncodingError(#[from] serde_urlencoded::ser::Error),
264
265 #[error("Unknown data type {data_type_id}")]
266 UnknownDataType { data_type_id: u8 },
267 #[error("Unknown value [{value}] for data type {data_type_xsd_iri:?}")]
268 UnknownValueForDataType {
269 data_type_xsd_iri: String,
270 value: String,
271 },
272 #[error("Unknown XSD data type {data_type_iri}")]
273 UnknownXsdDataType { data_type_iri: String },
274 #[error("Unknown literal value in N-Triples format: {value}")]
275 UnknownNTriplesValue { value: String },
276
277 #[cfg(feature = "tracing-subscriber")]
278 #[error(transparent)]
279 EnvFilterParseError(#[from] tracing_subscriber::filter::ParseError),
280
281 #[cfg(feature = "tracing-subscriber")]
282 #[error(transparent)]
283 TracingSubscriberError(#[from] tracing::subscriber::SetGlobalDefaultError),
284
285 #[cfg(feature = "tracing-subscriber")]
286 #[error(transparent)]
287 TracingSubscriberTryInitError(#[from] tracing_subscriber::util::TryInitError),
288
289 #[cfg(feature = "tracing-subscriber")]
290 #[error(transparent)]
291 FromEnvError(#[from] tracing_subscriber::filter::FromEnvError),
292
293 #[cfg(all(feature = "rdfox-support", not(target_arch = "wasm32")))]
294 #[error(transparent)]
295 R2D2Error(#[from] r2d2::Error),
296
297 #[error("While {action}: {message}")]
298 Exception { action: String, message: String },
299 #[error(
300 "The multiplicity ({multiplicity}) of a cursor row exceeded the maximum number of rows \
301 ({maxrow}) for query:\n{query}"
302 )]
303 MultiplicityExceededMaximumNumberOfRows {
304 maxrow: usize,
305 multiplicity: usize,
306 query: String,
307 },
308 #[error("Cannot get any argument indexes from the cursor of:\n{query}")]
309 CannotGetAnyArgumentIndexes { query: String },
310 #[error("Maximum number of rows ({maxrow}) has been exceeded for query:\n{query}")]
311 ExceededMaximumNumberOfRows { maxrow: usize, query: String },
312 #[error("Could not find a license key")]
313 RDFoxLicenseFileNotFound,
314 #[error("Unknown resource")]
315 UnknownResourceException,
316 #[error("Could not create RDFox server")]
317 CouldNotCreateRDFoxServer,
318 #[error("Could not import RDF File")]
319 CouldNotImportRDFFile,
320 #[error("Invalid prefix name")]
321 InvalidPrefixName,
322 #[error("Invalid literal value")]
323 InvalidLiteral,
324 #[error("Could not parse IRI: {0:?}")]
325 IriParseError(String),
326
327 #[cfg(not(target_arch = "wasm32"))]
328 #[error(transparent)]
329 DateParseError(#[from] chrono::ParseError),
330
331 #[cfg(all(feature = "rdfox-support", not(target_arch = "wasm32")))]
332 #[error(transparent)]
333 RDFoxError(#[from] rdfox_sys::Error),
334
335 #[error(transparent)]
336 FromPathError(#[from] relative_path::FromPathError),
337
338 #[error(transparent)]
339 StripPrefixError(#[from] std::path::StripPrefixError),
340}
341
342unsafe impl Send for Error {}
343
344#[cfg(all(feature = "salvo", not(target_arch = "wasm32")))]
345#[salvo::async_trait]
346impl salvo::Writer for Error {
347 async fn write(
348 mut self,
349 _req: &mut salvo::http::Request,
350 _depot: &mut salvo::Depot,
351 res: &mut salvo::http::Response,
352 ) {
353 res.status_code(salvo::http::StatusCode::INTERNAL_SERVER_ERROR);
354 res.render("custom error");
355 }
356}
357
358impl From<iref::InvalidIri<String>> for Error {
359 fn from(value: iref::InvalidIri<String>) -> Self { Error::InvalidIri(value.to_string()) }
360}
361
362impl From<iref::InvalidIri<&str>> for Error {
363 fn from(value: iref::InvalidIri<&str>) -> Self { Error::InvalidIri(value.to_string()) }
364}
365
366#[cfg(not(target_arch = "wasm32"))]
367impl<I: From<&'static str>> From<Error> for nom::Err<nom::error::Error<I>> {
368 fn from(_: Error) -> Self {
369 nom::Err::Error(nom::error::Error::new(
370 "unknown datastore error".into(),
371 nom::error::ErrorKind::Fail,
372 ))
373 }
374}