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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! The answers to a request this dashboard sent: what landed, what never
//! went out, and what a batch left unsent.
use super::*;
impl App {
/// `Msg::Replied`'s arm: routed by what was sent, to the handler that
/// asked for it.
pub(super) fn on_replied(
&mut self,
sent: Sent,
result: Result<Response, RequestError>,
) -> Effect {
match sent {
Sent::Lambs { id } => self.on_lambs(id, result),
Sent::Action { verb, target, name } => {
self.on_action_reply(verb, target, &name, result)
}
Sent::Dog {
name,
enable,
ticket,
..
} => self.on_dog_reply(name, enable, ticket, result),
Sent::GrantDog { name, ticket, .. } => self.on_dog_grant_reply(name, ticket, result),
Sent::SheepConfig { name } => self.on_sheep_config(&name, result),
Sent::DogSection { name } => self.on_dog_section(&name, result),
Sent::DogPane { name, opening } => self.on_dog_pane_pulled(&name, opening, result),
Sent::DogPaneAction {
name,
action,
label,
opening,
..
} => self.on_dog_pane_action_reply(&name, opening, &action, &label, result),
Sent::SetDogSection { name, ticket, .. } => {
self.on_dog_section_set(&name, ticket, result)
}
Sent::SetSheepDogTable {
name, dog, table, ..
} => self.on_table_set(&name, &dog, table.is_none(), result),
Sent::ApplyField {
name,
ticket,
key,
value,
..
} => {
let landed = result.is_ok();
let effect = self.on_field_applied(&name, &key, &value, result);
self.resolve_held_write(ticket, landed).unwrap_or(effect)
}
Sent::SetEnv {
name,
ticket,
key,
value,
..
} => {
let landed = result.is_ok();
let was_set = value.is_some();
let effect = self.on_env_set(&name, &key, was_set, result);
self.resolve_held_write(ticket, landed).unwrap_or(effect)
}
}
}
/// `Msg::Unsent`'s arm: a request the caller could not hand to the link
/// task, reported by what was sent.
pub(super) fn on_unsent(&mut self, sent: Sent) -> Effect {
match sent {
Sent::Action { verb, target, name } => {
self.action = None;
self.notice = Some(Notice::grave(
// No cause: `Full` is reachable while the shepherd is
// merely slow, so naming one would invent it.
format!("{}: it was not sent", target_prefix(verb, &target, &name)),
));
Effect::None
}
// A dropped lamb fetch already reads as "not read yet".
Sent::Lambs { .. } => Effect::None,
// A config read nobody took, reported rather than
// swallowed: silence here looks like a key that is not
// bound. A close waiting on it ends, having written nothing.
Sent::SheepConfig { name } => {
self.config_read_in_flight = false;
self.notice = Some(Notice::grave(format!(
"{name}: its config was not asked for{}",
self.end_close()
)));
Effect::None
}
// Both write arms name the field, and neither reaches for
// the pane: a close sends the whole set and leaves, so
// every one of these lands with no pane on screen. The
// notice is the whole report.
Sent::ApplyField { name, key, .. } => {
self.notice = Some(Notice::grave(format!("{name}: {key} was not sent")));
Effect::None
}
Sent::SetEnv { name, key, .. } => {
self.notice = Some(Notice::grave(format!("{name}: env {key} was not sent")));
Effect::None
}
// The dog twins of the two arms above: a read nobody took
// is reported, and so is a write nobody took.
Sent::DogSection { name } => {
self.config_read_in_flight = false;
// A settings row left mid-read would otherwise sit there
// holding nothing: the tree was put back to `Reading` for a
// re-read that never went out.
if self
.settings()
.is_some_and(|settings| settings.is_reading_a_dog(&name))
{
self.refuse_settings_dog(
&name,
format!("{name}: its config was not asked for"),
);
}
self.notice = Some(Notice::grave(format!(
"{name}: its config was not asked for{}",
self.end_close()
)));
Effect::None
}
// A pull nobody took: the pane says so rather than waiting on
// an answer that cannot come.
Sent::DogPane { name, opening } => self.land_dog_pane(
&name,
opening,
Err(format!("{name}: the pane was not asked for")),
),
Sent::DogPaneAction {
name,
action,
opening,
..
} => {
self.on_dog_pane_action_unsent(&name, opening, &action);
Effect::None
}
Sent::SetDogSection { name, ticket, .. } => {
// The write never left, so nothing is in flight: the prompt has
// to say so rather than sit at "sent" waiting on a reply that
// can no longer arrive.
if let Some(settings) = self.settings_mut() {
settings.resolve(ticket);
}
self.notice = Some(Notice::grave(format!("{name}: its config was not sent")));
Effect::None
}
Sent::SetSheepDogTable { name, dog, .. } => self.on_table_unsent(&name, &dog),
// The arm above, against the settings screen's pending line.
Sent::Dog {
name,
enable,
ticket,
..
} => {
if let Some(settings) = self.settings_mut() {
settings.resolve(ticket);
}
let verb = if enable { "enable" } else { "disable" };
self.notice = Some(Notice::grave(format!("{verb} {name}: it was not sent")));
Effect::None
}
// The record is already in the file by the time this half goes
// out, so the sentence says the shepherd was not told rather than
// that nothing happened.
Sent::GrantDog { name, ticket, .. } => {
if let Some(settings) = self.settings_mut() {
settings.resolve(ticket);
}
self.notice = Some(Notice::grave(format!(
"{name}: its new grants were not sent, and the running dog keeps the old ones"
)));
Effect::None
}
}
}
/// `Msg::BatchSent`'s arm.
///
/// Delegates to `Msg::Unsent`'s own match rather than repeating
/// it: every arm there already reports the right notice for the
/// `Sent` it carries, and returns `Effect::None`.
pub(super) fn on_batch_sent(&mut self, unsent: Option<Sent>) -> Effect {
match unsent {
Some(sent) => self.update(Msg::Unsent { sent }),
None => Effect::None,
}
}
}