From 068cc1dd4cd69cc77b4ee3cd9fa3c61452d1c62b Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 16 Jan 2024 13:58:49 +0900 Subject: [PATCH] Return io::ErrorKind::Unsupported for "unsupported" error --- src/error.rs | 2 ++ src/lib.rs | 1 + src/loader.rs | 26 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/error.rs b/src/error.rs index be3c77b..d64d38e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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) @@ -14,6 +15,7 @@ macro_rules! format_err { }; } +#[cfg(feature = "collada")] macro_rules! bail { ($($tt:tt)*) => { return Err(format_err!($($tt)*)) diff --git a/src/lib.rs b/src/lib.rs index df0c6f7..3e5dc55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ clippy::wildcard_imports, // TODO )] +#[cfg(any(feature = "collada", feature = "stl"))] #[macro_use] mod error; diff --git a/src/loader.rs b/src/loader.rs index d544ca7..2dd9b68 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -114,22 +114,28 @@ impl> Loader { #[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:?}", + )), } }