subspace_core/diagnostics/
error.rs1use chrono::{DateTime, Utc};
2
3#[derive(Clone)]
5pub struct ErrorDetails {
6 pub(super) title: String,
7 pub(super) message: String,
8 pub(super) stage: String,
9 pub(super) code: Option<String>,
10 pub(super) chain: Option<String>,
11 pub(super) time: ErrorTime,
12 pub(super) private_values: Vec<String>,
13}
14
15#[derive(Clone)]
16pub(super) enum ErrorTime {
17 Recorded(DateTime<Utc>),
18 Observed(DateTime<Utc>),
19}
20
21impl ErrorDetails {
23 pub fn new(
25 title: impl Into<String>,
26 message: impl Into<String>,
27 stage: impl Into<String>,
28 ) -> Self {
29 Self {
30 title: title.into(),
31 message: message.into(),
32 stage: stage.into(),
33 code: None,
34 chain: None,
35 time: ErrorTime::Observed(Utc::now()),
36 private_values: Vec::new(),
37 }
38 }
39
40 pub fn with_recorded_at(mut self, at: DateTime<Utc>) -> Self {
41 self.time = ErrorTime::Recorded(at);
42 self
43 }
44
45 #[cfg(test)]
46 pub(crate) fn with_observed_at(mut self, at: DateTime<Utc>) -> Self {
47 self.time = ErrorTime::Observed(at);
48 self
49 }
50
51 pub fn with_code(mut self, code: impl Into<String>) -> Self {
52 self.code = Some(code.into());
53 self
54 }
55
56 pub fn with_chain(mut self, chain: impl Into<String>) -> Self {
59 self.chain = Some(chain.into());
60 self
61 }
62
63 pub fn with_private_values(mut self, values: impl IntoIterator<Item = String>) -> Self {
68 self.private_values.extend(values);
69 super::redact::normalize_values(&mut self.private_values);
70 self
71 }
72}