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