Skip to content

Commit 684c1d6

Browse files
committed
Don't silently ignore postprocessing errors
1 parent d8b5e7f commit 684c1d6

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

src/generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn generate(
8484
}
8585

8686
if !flags.no_postprocess {
87-
postprocessor.run_postprocessor();
87+
postprocessor.run_postprocessor()?;
8888
}
8989

9090
Ok(())

src/postprocessing.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::{cell::RefCell, collections::BTreeSet, io, process::Command, sync::Mutex};
1+
use std::{cell::RefCell, io, process::Command};
22

3+
use anyhow::bail;
34
use camino::{Utf8Path, Utf8PathBuf};
45

56
#[derive(Debug, Clone)]
@@ -34,13 +35,13 @@ impl Postprocessor {
3435
Self::new(lang, output_dir.to_path_buf())
3536
}
3637

37-
pub(crate) fn run_postprocessor(&self) {
38+
pub(crate) fn run_postprocessor(&self) -> anyhow::Result<()> {
3839
match self.postprocessor_lang {
3940
// pass each file to postprocessor at once
4041
PostprocessorLanguage::Java | PostprocessorLanguage::Rust => {
4142
let commands = self.postprocessor_lang.postprocessing_commands();
4243
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())?;
4445
}
4546
}
4647
// pass output dir to postprocessor
@@ -52,11 +53,12 @@ impl Postprocessor {
5253
| PostprocessorLanguage::TypeScript => {
5354
let commands = self.postprocessor_lang.postprocessing_commands();
5455
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()])?;
5657
}
5758
}
5859
PostprocessorLanguage::Unknown => (),
5960
}
61+
Ok(())
6062
}
6163
pub(crate) fn add_path(&self, path: &Utf8Path) {
6264
let mut v = self.files_to_process.borrow_mut();
@@ -140,25 +142,20 @@ impl PostprocessorLanguage {
140142
}
141143
}
142144

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<()> {
144150
let result = Command::new(command).args(args).args(paths).status();
145151
match result {
146-
Ok(exit_status) if exit_status.success() => {}
152+
Ok(exit_status) if exit_status.success() => Ok(()),
147153
Ok(exit_status) => {
148-
tracing::warn!(exit_status = exit_status.code(), "`{command}` failed");
154+
bail!("`{command}` failed with exit code {:?}", exit_status.code());
149155
}
150156
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");
162158
}
159+
Err(e) => Err(e.into()),
163160
}
164161
}

0 commit comments

Comments
 (0)