@@ -3,8 +3,10 @@ use std::env;
3
3
use anyhow:: { anyhow, bail, Result } ;
4
4
use fs_err as fs;
5
5
use rustdoc_json_types:: { Crate , Id , FORMAT_VERSION } ;
6
+ use serde_json:: Value ;
6
7
7
8
pub ( crate ) mod item_kind;
9
+ mod json_find;
8
10
mod validator;
9
11
10
12
#[ derive( Debug ) ]
@@ -21,8 +23,10 @@ enum ErrorKind {
21
23
22
24
fn main ( ) -> Result < ( ) > {
23
25
let path = env:: args ( ) . nth ( 1 ) . ok_or_else ( || anyhow ! ( "no path given" ) ) ?;
24
- let contents = fs:: read_to_string ( path) ?;
26
+ let contents = fs:: read_to_string ( & path) ?;
25
27
let krate: Crate = serde_json:: from_str ( & contents) ?;
28
+ // TODO: Only load if nessessary.
29
+ let krate_json: Value = serde_json:: from_str ( & contents) ?;
26
30
assert_eq ! ( krate. format_version, FORMAT_VERSION ) ;
27
31
28
32
let mut validator = validator:: Validator :: new ( & krate) ;
@@ -31,11 +35,29 @@ fn main() -> Result<()> {
31
35
if !validator. errs . is_empty ( ) {
32
36
for err in validator. errs {
33
37
match err. kind {
34
- ErrorKind :: NotFound => eprintln ! ( "{}: Not Found" , err. id. 0 ) ,
38
+ ErrorKind :: NotFound => {
39
+ let sels =
40
+ json_find:: find_selector ( & krate_json, & Value :: String ( err. id . 0 . clone ( ) ) ) ;
41
+ match & sels[ ..] {
42
+ [ ] => unreachable ! (
43
+ "id must be in crate, or it wouldn't be reported as not found"
44
+ ) ,
45
+ [ sel] => eprintln ! (
46
+ "{} not in index or paths, but refered to at '{}'" ,
47
+ err. id. 0 ,
48
+ json_find:: to_jsonpath( & sel)
49
+ ) ,
50
+ [ sel, ..] => eprintln ! (
51
+ "{} not in index or paths, but refered to at '{}' and more" ,
52
+ err. id. 0 ,
53
+ json_find:: to_jsonpath( & sel)
54
+ ) ,
55
+ }
56
+ }
35
57
ErrorKind :: Custom ( msg) => eprintln ! ( "{}: {}" , err. id. 0 , msg) ,
36
58
}
37
59
}
38
- bail ! ( "Errors validating json" ) ;
60
+ bail ! ( "Errors validating json {path} " ) ;
39
61
}
40
62
41
63
Ok ( ( ) )
0 commit comments