@@ -3,8 +3,10 @@ use std::env;
33use anyhow:: { anyhow, bail, Result } ;
44use fs_err as fs;
55use rustdoc_json_types:: { Crate , Id , FORMAT_VERSION } ;
6+ use serde_json:: Value ;
67
78pub ( crate ) mod item_kind;
9+ mod json_find;
810mod validator;
911
1012#[ derive( Debug ) ]
@@ -21,8 +23,10 @@ enum ErrorKind {
2123
2224fn main ( ) -> Result < ( ) > {
2325 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) ?;
2527 let krate: Crate = serde_json:: from_str ( & contents) ?;
28+ // TODO: Only load if nessessary.
29+ let krate_json: Value = serde_json:: from_str ( & contents) ?;
2630 assert_eq ! ( krate. format_version, FORMAT_VERSION ) ;
2731
2832 let mut validator = validator:: Validator :: new ( & krate) ;
@@ -31,11 +35,29 @@ fn main() -> Result<()> {
3135 if !validator. errs . is_empty ( ) {
3236 for err in validator. errs {
3337 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+ }
3557 ErrorKind :: Custom ( msg) => eprintln ! ( "{}: {}" , err. id. 0 , msg) ,
3658 }
3759 }
38- bail ! ( "Errors validating json" ) ;
60+ bail ! ( "Errors validating json {path} " ) ;
3961 }
4062
4163 Ok ( ( ) )
0 commit comments