-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.rs
More file actions
53 lines (41 loc) · 1.46 KB
/
error.rs
File metadata and controls
53 lines (41 loc) · 1.46 KB
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
use stackable_cockpit::constants::{DEFAULT_NAMESPACE, DEFAULT_OPERATOR_NAMESPACE};
use crate::output::{ContextExt, ErrorReport, OutputKind};
#[derive(Debug, Default)]
pub struct ErrorContext {
post_hints: Vec<String>,
pre_hints: Vec<String>,
error_report: String,
no_color: bool,
}
impl ContextExt for ErrorContext {
fn into_context(self) -> tera::Context {
let mut ctx = tera::Context::new();
ctx.insert("default_operator_namespace", DEFAULT_OPERATOR_NAMESPACE);
ctx.insert("default_namespace", DEFAULT_NAMESPACE);
ctx.insert("post_hints", &self.post_hints);
ctx.insert("pre_hints", &self.pre_hints);
ctx.insert("error_report", &self.error_report);
ctx
}
fn output_kind(&self) -> OutputKind {
OutputKind::Error
}
fn set_no_color(&mut self, no_color: bool) {
self.no_color = no_color
}
}
impl ErrorContext {
pub fn with_error_report(&mut self, error: impl ErrorReport) -> &mut Self {
// We use expect here because we want to render the error report. If
// this fails, there is no point in catching an error while trying to
// render a different error.
self.error_report = error
.into_error_report()
.expect("failed to render error report");
self
}
pub fn with_post_hint(&mut self, post_hint: impl Into<String>) -> &mut Self {
self.post_hints.push(post_hint.into());
self
}
}