@@ -14,7 +14,7 @@ use log::{set_max_level, LevelFilter};
1414
1515// project specific modules/crates
1616use crate :: clang_tools:: capture_clang_tools_output;
17- use crate :: cli:: { ClangParams , Cli , FeedbackInput , LinesChangedOnly , SubCommand } ;
17+ use crate :: cli:: { ClangParams , Cli , CliCommand , FeedbackInput , LinesChangedOnly } ;
1818use crate :: common_fs:: FileFilter ;
1919use crate :: logger;
2020use crate :: rest_api:: { github:: GithubApiClient , RestApiClient } ;
@@ -43,7 +43,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
4343pub async fn run_main ( args : Vec < String > ) -> Result < ( ) > {
4444 let cli = Cli :: parse_from ( args) ;
4545
46- if matches ! ( cli. commands, Some ( SubCommand :: Version ) ) {
46+ if matches ! ( cli. commands, Some ( CliCommand :: Version ) ) {
4747 println ! ( "cpp-linter v{}" , VERSION ) ;
4848 return Ok ( ( ) ) ;
4949 }
@@ -57,12 +57,12 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
5757 }
5858
5959 if cli. source_options . repo_root != "." {
60- env:: set_current_dir ( Path :: new ( & cli. source_options . repo_root ) ) . unwrap_or_else ( |_ | {
61- panic ! (
62- "'{}' is inaccessible or does not exist" ,
60+ env:: set_current_dir ( Path :: new ( & cli. source_options . repo_root ) ) . map_err ( |e | {
61+ anyhow ! (
62+ "'{}' is inaccessible or does not exist: {e:?} " ,
6363 cli. source_options. repo_root
6464 )
65- } ) ;
65+ } ) ? ;
6666 }
6767
6868 let rest_api_client = GithubApiClient :: new ( ) ?;
@@ -240,4 +240,16 @@ mod test {
240240 . await ;
241241 assert ! ( result. is_ok( ) ) ;
242242 }
243+
244+ #[ tokio:: test]
245+ async fn bad_repo_root ( ) {
246+ env:: remove_var ( "GITHUB_OUTPUT" ) ; // avoid writing to GH_OUT in parallel-running tests
247+ let result = run_main ( vec ! [
248+ "cpp-linter" . to_string( ) ,
249+ "-r" . to_string( ) ,
250+ "some-non-existent-dir" . to_string( ) ,
251+ ] )
252+ . await ;
253+ assert ! ( result. is_err( ) ) ;
254+ }
243255}
0 commit comments