Skip to main content

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    /// The queue has node-pinned worker work whose topology the shell runtime
23    /// cannot express.
24    #[error(
25        "the document's `worker {task_queue}` block has node-pinned worker-owed actions, but \
26         `aion worker shell` cannot express node topology: it has no node flag, registers with \
27         the machine hostname as its node, and its startup check demands the whole worker-owed \
28         action set regardless of pins. Use `aion awl scaffold`'s Rust crate, which opens one \
29         connection per node, for this queue."
30    )]
31    NodePinnedQueue {
32        /// The queue containing at least one worker-owed node pin.
33        task_queue: String,
34    },
35    /// An action name that cannot name a Rust function.
36    #[error(
37        "action `{action}` of worker `{task_queue}` is not a Rust identifier, so the generated \
38         crate could not name a handler function after it"
39    )]
40    ActionNameNotAnIdentifier {
41        /// The queue declaring the action.
42        task_queue: String,
43        /// The offending action name.
44        action: String,
45    },
46    /// An action named after one of the three keywords with no raw form.
47    #[error(
48        "action `{action}` of worker `{task_queue}` is named after the Rust keyword `{action}`, \
49         which has no raw-identifier form, so the generated crate could not name a handler \
50         function after it"
51    )]
52    ActionNameUnnameable {
53        /// The queue declaring the action.
54        task_queue: String,
55        /// The offending action name.
56        action: String,
57    },
58    /// A crate name Cargo would refuse.
59    #[error(
60        "`{crate_name}` is not a usable Cargo package name; it must be non-empty and contain \
61         only ASCII letters, digits, `-`, and `_`"
62    )]
63    CrateNameInvalid {
64        /// The rejected package name.
65        crate_name: String,
66    },
67    /// An empty path where the generated crate needs one to reach the
68    /// document.
69    #[error(
70        "the generated crate needs a {role} path to reach the AWL document, and an empty one \
71         was supplied"
72    )]
73    DocumentPathEmpty {
74        /// Which path was empty: `include` or `directory`.
75        role: &'static str,
76    },
77    /// A schema that could not be rendered into the handler documentation.
78    #[error("the declared {role} schema of action `{action}` could not be rendered: {reason}")]
79    SchemaUnrenderable {
80        /// The action whose schema failed to render.
81        action: String,
82        /// `input` or `output`.
83        role: &'static str,
84        /// The serialization failure.
85        reason: String,
86    },
87}