Skip to content

Commit 87d436a

Browse files
committed
print errors as json in cli
1 parent da04745 commit 87d436a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tmc-langs-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rpassword = "4"
1818
url = "2"
1919
serde = "1"
2020
anyhow = "1"
21-
ansi_term = "0.12"
2221
quit = "1"
2322
dirs = "3"
2423

tmc-langs-cli/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! CLI client for TMC
22
3-
use ansi_term::Colour::Red;
43
use anyhow::{Context, Result};
54
use clap::{App, Arg, Error, ErrorKind, SubCommand};
65
use serde::Serialize;
@@ -26,7 +25,21 @@ fn main() {
2625
let _ = ansi_term::enable_ansi_support();
2726

2827
if let Err(e) = run() {
29-
eprintln!("{}: {:?}", Red.bold().paint("error"), e);
28+
let mut causes = vec![];
29+
let mut next_source = e.source();
30+
while let Some(source) = next_source {
31+
causes.push(format!("Caused by: {}", source.to_string()));
32+
next_source = source.source();
33+
}
34+
let error = serde_json::json! {
35+
{
36+
"error": {
37+
"message": e.to_string(),
38+
"causes": causes,
39+
}
40+
}
41+
};
42+
println!("{:#}", error);
3043
quit::with_code(1);
3144
}
3245
}

0 commit comments

Comments
 (0)