better error handling

This commit is contained in:
Emma Tebibyte 2024-04-24 20:34:57 -06:00
parent 72c46447c1
commit 79189561c6
Signed by: emma
GPG Key ID: 06FA419A1698C270
1 changed files with 6 additions and 10 deletions

View File

@ -29,7 +29,7 @@
use std::{
io::{ Error, Write },
process::{ Command, exit, Stdio },
process::{ Command, Stdio },
path::PathBuf,
};
@ -51,11 +51,9 @@ fn main() -> Result<(), Error> {
let output = process.wait_with_output()?.stdout;
let headers = String::from_utf8(output).unwrap_or_else( |e| {
Error::other(e.to_string());
/* Exit with status 1 because were bootstrapping sysexits.h, silly! */
exit(1);
});
let headers = String::from_utf8(output).map_err(|e| {
Error::other(e.to_string())
})?;
/* Split headers by spaces because cpp(1) returns more than one */
for h in headers.split(' ') {
@ -73,11 +71,9 @@ fn main() -> Result<(), Error> {
.header(header)
.parse_callbacks(Box::new(CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings.");
.map_err(|e| Error::other(e.to_string()))?;
bindings
.write_to_file(PathBuf::from("src/").join("lib.rs"))
.expect("Couldn't write bindings!");
bindings.write_to_file(PathBuf::from("src/").join("lib.rs"))?;
Ok(())
}