Handle non-utf8 input file with better error
diff --git a/gen/src/error.rs b/gen/src/error.rs
index f140577..b269286 100644
--- a/gen/src/error.rs
+++ b/gen/src/error.rs
@@ -8,8 +8,9 @@
use std::fmt::{self, Display};
use std::io::{self, Write};
use std::ops::Range;
-use std::path::Path;
+use std::path::{Path, PathBuf};
use std::process;
+use std::str::Utf8Error;
pub(crate) type Result<T, E = Error> = std::result::Result<T, E>;
@@ -17,6 +18,7 @@
pub(crate) enum Error {
NoBridgeMod,
Fs(fs::Error),
+ Utf8(PathBuf, Utf8Error),
Syn(syn::Error),
}
@@ -25,6 +27,7 @@
match self {
Error::NoBridgeMod => write!(f, "no #[cxx::bridge] module found"),
Error::Fs(err) => err.fmt(f),
+ Error::Utf8(path, _) => write!(f, "Failed to read file `{}`", path.display()),
Error::Syn(err) => err.fmt(f),
}
}
@@ -34,6 +37,7 @@
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::Fs(err) => err.source(),
+ Error::Utf8(_, err) => Some(err),
Error::Syn(err) => err.source(),
_ => None,
}