Skip to content

Commit fc5ac7b

Browse files
MikuroXinaemilio
authored andcommitted
More detailed error
1 parent 24cfccd commit fc5ac7b

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/lib.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,17 +2150,25 @@ fn ensure_libclang_is_loaded() {}
21502150
#[derive(Debug)]
21512151
#[non_exhaustive]
21522152
pub enum BindgenError {
2153-
/// Any provided header was invalid.
2154-
InvalidHeader(String),
2153+
/// The header was a folder.
2154+
FolderAsHeader(String),
2155+
/// Permissions to read the header is insufficient.
2156+
InsufficientPermissions(String),
2157+
/// The header does not exist.
2158+
NotExist(String),
21552159
/// Clang diagnosed an error.
21562160
ClangDiagnostic(String),
21572161
}
21582162

21592163
impl std::fmt::Display for BindgenError {
21602164
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21612165
match self {
2162-
BindgenError::InvalidHeader(message) => {
2163-
write!(f, "invalid header: {}", message)
2166+
BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h),
2167+
BindgenError::InsufficientPermissions(h) => {
2168+
write!(f, "insufficient permissions to read '{}'", h)
2169+
}
2170+
BindgenError::NotExist(h) => {
2171+
write!(f, "header '{}' does not exist.", h)
21642172
}
21652173
BindgenError::ClangDiagnostic(message) => {
21662174
write!(f, "clang diagnosed error: {}", message)
@@ -2347,23 +2355,16 @@ impl Bindings {
23472355
if let Some(h) = options.input_header.as_ref() {
23482356
if let Ok(md) = std::fs::metadata(h) {
23492357
if md.is_dir() {
2350-
return Err(BindgenError::InvalidHeader(format!(
2351-
"'{}' is a folder",
2352-
h
2353-
)));
2358+
return Err(BindgenError::FolderAsHeader(h.into()));
23542359
}
23552360
if !can_read(&md.permissions()) {
2356-
return Err(BindgenError::InvalidHeader(format!(
2357-
"insufficient permissions to read '{}'",
2358-
h
2359-
)));
2361+
return Err(BindgenError::InsufficientPermissions(
2362+
h.into(),
2363+
));
23602364
}
23612365
options.clang_args.push(h.clone())
23622366
} else {
2363-
return Err(BindgenError::InvalidHeader(format!(
2364-
"header '{}' does not exist.",
2365-
h
2366-
)));
2367+
return Err(BindgenError::NotExist(h.into()));
23672368
}
23682369
}
23692370

0 commit comments

Comments
 (0)