From c6b1d11700bf5d2cbbd68e89359ee192b146dcae Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Fri, 13 Jun 2025 14:02:14 -0400 Subject: [PATCH] Fix to not panic when using the wrong argument type (#7474) --- rust/kcl-lib/src/std/args.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rust/kcl-lib/src/std/args.rs b/rust/kcl-lib/src/std/args.rs index e8b05a130..0afe72cec 100644 --- a/rust/kcl-lib/src/std/args.rs +++ b/rust/kcl-lib/src/std/args.rs @@ -166,8 +166,12 @@ impl Args { KclError::new_semantic(KclErrorDetails::new(message, arg.source_ranges())) })?; - // TODO unnecessary cloning - Ok(T::from_kcl_val(&arg).unwrap()) + T::from_kcl_val(&arg).ok_or_else(|| { + KclError::new_internal(KclErrorDetails::new( + format!("Mismatch between type coercion and value extraction (this isn't your fault).\nTo assist in bug-reporting, expected type: {ty:?}; actual value: {arg:?}"), + vec![self.source_range], + )) + }) } /// Get a labelled keyword arg, check it's an array, and return all items in the array