git.delta.rocks / jrsonnet / refs/commits / a307cfd45f8d

difftreelog

feat improve error display

Лач2020-06-04parent: #03f24e7.patch.diff
in: master

2 files changed

modifiedcmds/jsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jsonnet/Cargo.toml
+++ b/cmds/jsonnet/Cargo.toml
@@ -13,4 +13,4 @@
 [dependencies.clap]
 version = "3.0.0-beta.1"
 default-features = false
-features = ["std", "derive", "suggestions", "color", "unstable", "wrap_help"]
+features = ["std", "derive"]
modifiedcmds/jsonnet/src/main.rsdiffbeforeafterboth
1use clap::Clap;1use clap::Clap;
2use jsonnet_evaluator::Val;
23
3#[derive(Clap)]4#[derive(Clap)]
4#[clap(version = "0.1.0", author = "Lach <iam@lach.pw>")]5#[clap(version = "0.1.0", author = "Lach <iam@lach.pw>")]
21 String::from_utf8(std::fs::read(opts.input.clone()).unwrap()).unwrap(),22 String::from_utf8(std::fs::read(opts.input.clone()).unwrap()).unwrap(),
22 )23 )
23 .unwrap();24 .unwrap();
24 let result = evaluator.evaluate_file(&opts.input.clone());25 let result = evaluator.evaluate_file(&opts.input);
25 match result {26 match result {
26 Ok(v) => println!("{:?}", v),27 Ok(v) => match v {
28 Val::Str(s) => println!("{}", s),
29 Val::Num(n) => println!("{}", n),
30 _v => eprintln!(
31 "jsonnet output is not a string.\nDid you forgot to set --format, or wrap your data with std.manifestJson?"
32 ),
33 },
27 Err(err) => {34 Err(err) => {
35 println!("Error: {:?}", err.0);
28 use annotate_snippets::{36 use annotate_snippets::{
29 display_list::{DisplayList, FormatOptions},37 display_list::{DisplayList, FormatOptions},
30 snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},38 snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
31 };39 };
32 for item in (err.1).0.iter() {40 for item in (err.1).0.iter() {
41 let desc = &item.1;
42 if (item.0).1.is_none() {
43 continue;
44 }
33 let source = (item.0).1.clone().unwrap();45 let source = (item.0).1.clone().unwrap();
34 let code = evaluator.get_source(&source.0);46 let code = evaluator.get_source(&source.0);
35 let snippet = Snippet {47 let snippet = Snippet {
49 origin: Some(&source.0),61 origin: Some(&source.0),
50 fold: true,62 fold: true,
51 annotations: vec![SourceAnnotation {63 annotations: vec![SourceAnnotation {
52 label: &"Example error annotation",64 label: desc,
53 annotation_type: AnnotationType::Error,65 annotation_type: AnnotationType::Error,
54 range: (source.1, source.2),66 range: (source.1, source.2),
55 }],67 }],