From 5e43f2e5a4b56ea8789c2090390f287474e9ac04 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 28 Sep 2020 11:19:49 +0800 Subject: [PATCH] Better error handling messages. --- src/any.rs | 4 ++-- src/module/resolvers/collection.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/any.rs b/src/any.rs index 7cc67870..10133b43 100644 --- a/src/any.rs +++ b/src/any.rs @@ -643,7 +643,7 @@ impl Dynamic { }; #[cfg(feature = "no_closure")] - panic!("'no_closure' feature does not support converting into a shared value"); + panic!("converting into a shared value is not supported under 'no_closure'"); } /// Convert the `Dynamic` value into specific type. @@ -812,7 +812,7 @@ impl Dynamic { self.try_cast::().unwrap_or_else(|| { panic!( - "value is {} and cannot be cast to {}", + "cannot cast {} value and to {}", self_type_name, type_name::() ) diff --git a/src/module/resolvers/collection.rs b/src/module/resolvers/collection.rs index b8cc2729..e513f51e 100644 --- a/src/module/resolvers/collection.rs +++ b/src/module/resolvers/collection.rs @@ -70,8 +70,13 @@ impl ModuleResolver for ModuleResolversCollection { pos: Position, ) -> Result> { for resolver in self.0.iter() { - if let Ok(module) = resolver.resolve(engine, path, pos) { - return Ok(module); + match resolver.resolve(engine, path, pos) { + Ok(module) => return Ok(module), + Err(err) => match *err { + EvalAltResult::ErrorModuleNotFound(_, _) => continue, + EvalAltResult::ErrorInModule(_, err, _) => return Err(err), + _ => panic!("ModuleResolver::resolve returns error that is not ErrorModuleNotFound or ErrorInModule"), + }, } }