diff options
author | MikuroXina <ryosukadnak@gmail.com> | 2021-12-08 13:49:54 +0900 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-12-29 20:39:01 +0100 |
commit | fc5ac7b4397b5a90ae0a045d672455ecce5dc485 (patch) | |
tree | b059e20100e0f7166d583e1e32248dae796e77cb /src | |
parent | 24cfccd9c5d1d4b4be9bfba3c28c758486fe15cd (diff) |
More detailed error
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -2150,8 +2150,12 @@ fn ensure_libclang_is_loaded() {} #[derive(Debug)] #[non_exhaustive] pub enum BindgenError { - /// Any provided header was invalid. - InvalidHeader(String), + /// The header was a folder. + FolderAsHeader(String), + /// Permissions to read the header is insufficient. + InsufficientPermissions(String), + /// The header does not exist. + NotExist(String), /// Clang diagnosed an error. ClangDiagnostic(String), } @@ -2159,8 +2163,12 @@ pub enum BindgenError { impl std::fmt::Display for BindgenError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - BindgenError::InvalidHeader(message) => { - write!(f, "invalid header: {}", message) + BindgenError::FolderAsHeader(h) => write!(f, "'{}' is a folder", h), + BindgenError::InsufficientPermissions(h) => { + write!(f, "insufficient permissions to read '{}'", h) + } + BindgenError::NotExist(h) => { + write!(f, "header '{}' does not exist.", h) } BindgenError::ClangDiagnostic(message) => { write!(f, "clang diagnosed error: {}", message) @@ -2347,23 +2355,16 @@ impl Bindings { if let Some(h) = options.input_header.as_ref() { if let Ok(md) = std::fs::metadata(h) { if md.is_dir() { - return Err(BindgenError::InvalidHeader(format!( - "'{}' is a folder", - h - ))); + return Err(BindgenError::FolderAsHeader(h.into())); } if !can_read(&md.permissions()) { - return Err(BindgenError::InvalidHeader(format!( - "insufficient permissions to read '{}'", - h - ))); + return Err(BindgenError::InsufficientPermissions( + h.into(), + )); } options.clang_args.push(h.clone()) } else { - return Err(BindgenError::InvalidHeader(format!( - "header '{}' does not exist.", - h - ))); + return Err(BindgenError::NotExist(h.into())); } } |