1+ use color_eyre:: { eyre:: Context , Result } ;
12use ownership:: { Ownership , ValidationErrors } ;
2- use tracing:: debug;
33
44use crate :: project:: Project ;
55use clap:: { Parser , Subcommand } ;
66use path_clean:: PathClean ;
77use std:: {
8- error:: Error ,
98 fs:: File ,
109 path:: { Path , PathBuf } ,
1110 process,
@@ -47,44 +46,42 @@ struct Args {
4746}
4847
4948impl Args {
50- fn absolute_project_root ( & self ) -> Result < PathBuf , std:: io:: Error > {
51- self . project_root . canonicalize ( )
49+ fn absolute_project_root ( & self ) -> Result < PathBuf > {
50+ self . project_root
51+ . canonicalize ( )
52+ . with_context ( || format ! ( "Can't canonizalize {}" , self . project_root. to_string_lossy( ) ) )
5253 }
5354
54- fn absolute_config_path ( & self ) -> Result < PathBuf , std :: io :: Error > {
55+ fn absolute_config_path ( & self ) -> Result < PathBuf > {
5556 Ok ( self . absolute_path ( & self . config_path ) ?. clean ( ) )
5657 }
5758
58- fn absolute_codeowners_path ( & self ) -> Result < PathBuf , std :: io :: Error > {
59+ fn absolute_codeowners_path ( & self ) -> Result < PathBuf > {
5960 Ok ( self . absolute_path ( & self . codeowners_file_path ) ?. clean ( ) )
6061 }
6162
62- fn absolute_path ( & self , path : & Path ) -> Result < PathBuf , std :: io :: Error > {
63+ fn absolute_path ( & self , path : & Path ) -> Result < PathBuf > {
6364 Ok ( self . absolute_project_root ( ) ?. join ( path) )
6465 }
6566}
6667
67- fn main ( ) -> Result < ( ) , Box < dyn Error > > {
68+ fn main ( ) -> Result < ( ) > {
69+ color_eyre:: install ( ) ?;
6870 install_logger ( ) ;
6971 print_validation_errors_to_stdout ( cli ( ) ) ?;
7072
7173 Ok ( ( ) )
7274}
7375
74- fn cli ( ) -> Result < ( ) , Box < dyn Error > > {
76+ fn cli ( ) -> Result < ( ) > {
7577 let args = Args :: parse ( ) ;
7678
7779 let config_path = args. absolute_config_path ( ) ?;
7880 let codeowners_file_path = args. absolute_codeowners_path ( ) ?;
7981 let project_root = args. absolute_project_root ( ) ?;
8082
81- debug ! (
82- config_path = & config_path. to_str( ) ,
83- codeowners_file_path = & codeowners_file_path. to_str( ) ,
84- project_root = & project_root. to_str( ) ,
85- ) ;
86-
87- let config = serde_yaml:: from_reader ( File :: open ( config_path) ?) ?;
83+ let config =
84+ serde_yaml:: from_reader ( File :: open ( & config_path) . with_context ( || format ! ( "Can't open {}" , config_path. to_string_lossy( ) ) ) ?) ?;
8885 let ownership = Ownership :: build ( Project :: build ( & project_root, & codeowners_file_path, & config) ?) ;
8986 let command = args. command ;
9087
@@ -102,7 +99,7 @@ fn cli() -> Result<(), Box<dyn Error>> {
10299 Ok ( ( ) )
103100}
104101
105- fn print_validation_errors_to_stdout ( result : Result < ( ) , Box < dyn Error > > ) -> Result < ( ) , Box < dyn Error > > {
102+ fn print_validation_errors_to_stdout ( result : Result < ( ) > ) -> Result < ( ) > {
106103 if let Err ( error) = result {
107104 if let Some ( validation_errors) = error. downcast_ref :: < ValidationErrors > ( ) {
108105 println ! ( "{}" , validation_errors) ;
0 commit comments