build_pretty/
build_pretty_error.rs1use std::process::Output;
2
3use thiserror::Error;
4
5pub type BoxedDynStdError = Box<dyn std::error::Error>;
6
7#[derive(Error, Debug)]
8pub enum BuildPrettyError
9{
10 #[error("command was failed: task_name={task_name:?} task_index={task_index:?} output={output:?} error_source={error_source:?}")]
11 CommandWasFailed
12 {
13 task_name: &'static str,
14 task_index: usize,
15 output: Option<Output>,
16 error_source: Option<Box<dyn std::error::Error>>
17 },
18
19 #[error("fn was failed: task_name={task_name:?} task_index={task_index:?} output={output:?} error_source={error_source:?}")]
20 FnWasFailed
21 {
22 task_name: &'static str,
23 task_index: usize,
24 output: String,
25 error_source: Option<Box<dyn std::error::Error>>
26 }
27}
28
29impl BuildPrettyError
30{
31 pub fn extract_output(&self) -> String
32 {
33 match self
34 {
35 Self::CommandWasFailed {
36 task_name: _,
37 task_index: _,
38 output,
39 error_source: _
40 } =>
41 {
42 match output
43 {
44 Some(o) => format!("{}\n{}", String::from_utf8_lossy(&o.stdout), String::from_utf8_lossy(&o.stderr)),
45 None => String::new()
46 }
47 },
48 Self::FnWasFailed {
49 task_name: _,
50 task_index: _,
51 output,
52 error_source: _
53 } => output.clone()
54 }
55 }
56}