Skip to content

Commit

Permalink
Return io::ErrorKind::Unsupported for "unsupported" error
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 16, 2024
1 parent 4660400 commit 068cc1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{fmt, path::Path};
#[cfg(feature = "stl")]
use crate::utils::bytes::{bytecount_naive, memrchr_naive};

#[cfg(feature = "collada")]
macro_rules! format_err {
($msg:expr $(,)?) => {
crate::error::invalid_data($msg)
Expand All @@ -14,6 +15,7 @@ macro_rules! format_err {
};
}

#[cfg(feature = "collada")]
macro_rules! bail {
($($tt:tt)*) => {
return Err(format_err!($($tt)*))
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
clippy::wildcard_imports, // TODO
)]

#[cfg(any(feature = "collada", feature = "stl"))]
#[macro_use]
mod error;

Expand Down
26 changes: 16 additions & 10 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,28 @@ impl<B: AsRef<[u8]>> Loader<B> {
#[cfg(feature = "stl")]
Some("stl" | "STL") => self.load_stl_from_slice_(bytes, path),
#[cfg(not(feature = "stl"))]
Some("stl" | "STL") => {
bail!("'stl' feature of mesh-loader must be enabled to parse STL");
}
Some("stl" | "STL") => Err(io::Error::new(
io::ErrorKind::Unsupported,
"'stl' feature of mesh-loader must be enabled to parse STL file ({path:?})",
)),
#[cfg(feature = "collada")]
Some("dae" | "DAE") => self.load_from_slice_(bytes, path),
#[cfg(not(feature = "collada"))]
Some("dae" | "DAE") => {
bail!("'collada' feature of mesh-loader must be enabled to parse COLLADA");
}
Some("dae" | "DAE") => Err(io::Error::new(
io::ErrorKind::Unsupported,
"'collada' feature of mesh-loader must be enabled to parse COLLADA file ({path:?})",
)),
// #[cfg(feature = "obj")]
// Some("obj" | "OBJ") => self.load_obj_(path),
// #[cfg(not(feature = "obj"))]
// Some("obj" | "OBJ") => {
// bail!("'obj' feature of mesh-loader must be enabled to parse OBJ");
// }
_ => bail!("unsupported or unrecognized file type {path:?}"),
// Some("obj" | "OBJ") => Err(io::Error::new(
// io::ErrorKind::Unsupported,
// "'obj' feature of mesh-loader must be enabled to parse OBJ file ({path:?})",
// )),
_ => Err(io::Error::new(
io::ErrorKind::Unsupported,
"unsupported or unrecognized file type {path:?}",
)),
}
}

Expand Down

0 comments on commit 068cc1d

Please sign in to comment.