aion_package/codegen/awl_worker/error.rs
1//! Refusals from the AWL worker scaffold generator.
2//!
3//! Every one of these is a case where a crate COULD be emitted and would then
4//! fail to compile, fail admission, or serve nothing. A generated skeleton
5//! that does not compile is worse than no skeleton, so each is a refusal at
6//! generation time carrying what the author must change.
7
8/// Why a worker scaffold could not be generated.
9#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
10pub enum AwlScaffoldError {
11 /// Every action the queue declares carries a declarative body, so the
12 /// server executes all of them and there is no worker to write.
13 #[error(
14 "the document's `worker {task_queue}` block declares no action for an out-of-band \
15 worker: every action it declares carries a `run` body, which the server executes \
16 itself. There is nothing for a worker to serve."
17 )]
18 NoServableAction {
19 /// The queue (worker block) that declares only bodied actions.
20 task_queue: String,
21 },
22 /// An action name that cannot name a Rust function.
23 #[error(
24 "action `{action}` of worker `{task_queue}` is not a Rust identifier, so the generated \
25 crate could not name a handler function after it"
26 )]
27 ActionNameNotAnIdentifier {
28 /// The queue declaring the action.
29 task_queue: String,
30 /// The offending action name.
31 action: String,
32 },
33 /// An action named after one of the three keywords with no raw form.
34 #[error(
35 "action `{action}` of worker `{task_queue}` is named after the Rust keyword `{action}`, \
36 which has no raw-identifier form, so the generated crate could not name a handler \
37 function after it"
38 )]
39 ActionNameUnnameable {
40 /// The queue declaring the action.
41 task_queue: String,
42 /// The offending action name.
43 action: String,
44 },
45 /// A crate name Cargo would refuse.
46 #[error(
47 "`{crate_name}` is not a usable Cargo package name; it must be non-empty and contain \
48 only ASCII letters, digits, `-`, and `_`"
49 )]
50 CrateNameInvalid {
51 /// The rejected package name.
52 crate_name: String,
53 },
54 /// An empty path where the generated crate needs one to reach the
55 /// document.
56 #[error(
57 "the generated crate needs a {role} path to reach the AWL document, and an empty one \
58 was supplied"
59 )]
60 DocumentPathEmpty {
61 /// Which path was empty: `include` or `directory`.
62 role: &'static str,
63 },
64 /// A schema that could not be rendered into the handler documentation.
65 #[error("the declared {role} schema of action `{action}` could not be rendered: {reason}")]
66 SchemaUnrenderable {
67 /// The action whose schema failed to render.
68 action: String,
69 /// `input` or `output`.
70 role: &'static str,
71 /// The serialization failure.
72 reason: String,
73 },
74}