1
- use std:: { cell:: RefCell , collections :: BTreeSet , io, process:: Command , sync :: Mutex } ;
1
+ use std:: { cell:: RefCell , io, process:: Command } ;
2
2
3
+ use anyhow:: bail;
3
4
use camino:: { Utf8Path , Utf8PathBuf } ;
4
5
5
6
#[ derive( Debug , Clone ) ]
@@ -34,13 +35,13 @@ impl Postprocessor {
34
35
Self :: new ( lang, output_dir. to_path_buf ( ) )
35
36
}
36
37
37
- pub ( crate ) fn run_postprocessor ( & self ) {
38
+ pub ( crate ) fn run_postprocessor ( & self ) -> anyhow :: Result < ( ) > {
38
39
match self . postprocessor_lang {
39
40
// pass each file to postprocessor at once
40
41
PostprocessorLanguage :: Java | PostprocessorLanguage :: Rust => {
41
42
let commands = self . postprocessor_lang . postprocessing_commands ( ) ;
42
43
for ( command, args) in commands {
43
- execute_command ( command, args, & self . files_to_process . borrow ( ) ) ;
44
+ execute_command ( command, args, & self . files_to_process . borrow ( ) ) ? ;
44
45
}
45
46
}
46
47
// pass output dir to postprocessor
@@ -52,11 +53,12 @@ impl Postprocessor {
52
53
| PostprocessorLanguage :: TypeScript => {
53
54
let commands = self . postprocessor_lang . postprocessing_commands ( ) ;
54
55
for ( command, args) in commands {
55
- execute_command ( command, args, & vec ! [ self . output_dir. clone( ) ] ) ;
56
+ execute_command ( command, args, & vec ! [ self . output_dir. clone( ) ] ) ? ;
56
57
}
57
58
}
58
59
PostprocessorLanguage :: Unknown => ( ) ,
59
60
}
61
+ Ok ( ( ) )
60
62
}
61
63
pub ( crate ) fn add_path ( & self , path : & Utf8Path ) {
62
64
let mut v = self . files_to_process . borrow_mut ( ) ;
@@ -140,25 +142,20 @@ impl PostprocessorLanguage {
140
142
}
141
143
}
142
144
143
- fn execute_command ( command : & ' static str , args : & [ & str ] , paths : & Vec < Utf8PathBuf > ) {
145
+ fn execute_command (
146
+ command : & ' static str ,
147
+ args : & [ & str ] ,
148
+ paths : & Vec < Utf8PathBuf > ,
149
+ ) -> anyhow:: Result < ( ) > {
144
150
let result = Command :: new ( command) . args ( args) . args ( paths) . status ( ) ;
145
151
match result {
146
- Ok ( exit_status) if exit_status. success ( ) => { }
152
+ Ok ( exit_status) if exit_status. success ( ) => Ok ( ( ) ) ,
147
153
Ok ( exit_status) => {
148
- tracing :: warn! ( exit_status = exit_status . code ( ) , "`{command}` failed" ) ;
154
+ bail ! ( "`{command}` failed with exit code {:?}" , exit_status . code ( ) ) ;
149
155
}
150
156
Err ( e) if e. kind ( ) == io:: ErrorKind :: NotFound => {
151
- // only print one error per command that's not found
152
- static NOT_FOUND_LOGGED_FOR : Mutex < BTreeSet < & str > > = Mutex :: new ( BTreeSet :: new ( ) ) ;
153
- if NOT_FOUND_LOGGED_FOR . lock ( ) . unwrap ( ) . insert ( command) {
154
- tracing:: warn!( "`{command}` not found" ) ;
155
- }
156
- }
157
- Err ( e) => {
158
- tracing:: warn!(
159
- error = & e as & dyn std:: error:: Error ,
160
- "running `{command}` failed"
161
- ) ;
157
+ bail ! ( "`{command}` not found - run with --no-postprocessing to skip" ) ;
162
158
}
159
+ Err ( e) => Err ( e. into ( ) ) ,
163
160
}
164
161
}
0 commit comments