Skip to content

Commit 81121e5

Browse files
committed
log: Log errors presented to the user in templates
1 parent 8a8a135 commit 81121e5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/state/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ impl AppStateError {
3030
}
3131
inner_errors
3232
}
33+
34+
// Format an error for the logs
35+
pub fn log(&self) {
36+
log::error!("{self}");
37+
for error in self.iter_chain().skip(1) {
38+
log::error!("-> {error}");
39+
}
40+
}
3341
}
3442

3543
/// Global error page generated from an [AppStateError].
@@ -51,6 +59,8 @@ pub struct AppStateErrorContextInner {
5159

5260
impl From<AppStateError> for AppStateErrorContext {
5361
fn from(e: AppStateError) -> Self {
62+
// An error is being displayed to the user, make sure it's also written in the logs
63+
e.log();
5464
Self {
5565
state: AppStateErrorContextInner { errors: vec![e] },
5666
}

0 commit comments

Comments
 (0)