Skip to content

Commit 549ca93

Browse files
committed
gtk4-macros: Wait for blueprint-compiler process in all branches
Otherwise clippy complains and zombie processes might stay around. Also make sure to never panic on normal errors for the same reason, and provide more useful error messages.
1 parent 8497a9e commit 549ca93

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

gtk4-macros/src/blueprint.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use std::{
4-
io::{Error, ErrorKind, Result, Write},
4+
io::Write,
55
process::{Command, Stdio},
66
};
77

8-
pub(crate) fn compile_blueprint(blueprint: &[u8]) -> Result<String> {
8+
pub(crate) fn compile_blueprint(blueprint: &[u8]) -> Result<String, String> {
99
let mut compiler = Command::new("blueprint-compiler")
1010
.args(["compile", "-"])
1111
.stdin(Stdio::piped())
1212
.stdout(Stdio::piped())
1313
.spawn()
14-
.unwrap_or_else(|_| panic!("blueprint-compiler not found"));
14+
.map_err(|e| format!("blueprint-compiler couldn't be spawned: {e}"))?;
1515
let mut stdin = compiler.stdin.take().unwrap();
16-
stdin.write_all(blueprint)?;
16+
if let Err(e) = stdin.write_all(blueprint) {
17+
let _ = compiler.wait();
18+
return Err(format!(
19+
"Couldn't send blueprint to blueprint-compiler: {e}"
20+
));
21+
}
1722
drop(stdin);
1823

1924
let output = compiler
2025
.wait_with_output()
21-
.unwrap_or_else(|e| panic!("blueprint-compiler process failed {e}"));
26+
.map_err(|e| format!("blueprint-compiler process failed: {e}"))?;
2227

2328
let buf = String::from_utf8(output.stdout).unwrap();
24-
2529
if !buf.starts_with('<') {
26-
return Err(Error::new(ErrorKind::Other, buf));
30+
return Err(format!("blueprint-compiler failed: {buf}"));
2731
}
2832

2933
Ok(buf)

0 commit comments

Comments
 (0)