Skip to main content

tablo_core/declaration/
action_input.rs

1//! The declaration mistakes of an action's input, and their wording.
2
3use std::fmt;
4
5/// Why an action's input cannot be served:
6/// [`DeclarationErrorKind::ActionInput`](super::DeclarationErrorKind::ActionInput).
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum ActionInputFault {
10    /// A field named like a key the action's POST carries itself: `csrf_token`, `confirm` or
11    /// `ids`.
12    ///
13    /// Rename the field.
14    ReservedField(String),
15    /// A file field, whose upload an action's POST does not read.
16    ///
17    /// Take the file in a record form.
18    FileField(String),
19    /// No field, but a parse that refuses an empty submission, so the action could never run.
20    ///
21    /// Declare the fields it parses, or use `()`.
22    RefusesEmpty,
23    /// A dependent choice, whose options no route serves an action's input.
24    ///
25    /// Drop `depends_on`.
26    DependentChoice(String),
27    /// A [`Submits`](crate::Submits) button picking a field that renders no checkbox, which the
28    /// button could not post `true` to.
29    ///
30    /// Pick a `bool` field.
31    SubmitNotCheckbox(String),
32}
33
34/// [`DeclarationErrorKind::ActionInput`](super::DeclarationErrorKind::ActionInput)'s sentence.
35pub(super) fn fmt_action_input(
36    f: &mut fmt::Formatter<'_>,
37    action: &str,
38    fault: &ActionInputFault,
39) -> fmt::Result {
40    match fault {
41        ActionInputFault::ReservedField(field) => write!(
42            f,
43            "action '{action}' declares an input field named '{field}', which its POST \
44             carries itself: rename the field"
45        ),
46        ActionInputFault::FileField(field) => write!(
47            f,
48            "action '{action}' declares a file field '{field}' in its input, which an \
49             action's POST does not upload: take the file in a record form"
50        ),
51        ActionInputFault::RefusesEmpty => write!(
52            f,
53            "action '{action}' declares no input field, but its input refuses an empty \
54             submission: declare the fields it parses, or name `()`"
55        ),
56        ActionInputFault::DependentChoice(field) => write!(
57            f,
58            "action '{action}' declares a dependent choice '{field}' in its input, whose \
59             options only a resource's form refreshes: drop `depends_on`"
60        ),
61        ActionInputFault::SubmitNotCheckbox(field) => write!(
62            f,
63            "action '{action}' declares a submit checking '{field}', which renders no \
64             checkbox in its input: pick a `bool` field"
65        ),
66    }
67}