diff --git a/src/wasm-lib/kcl/src/ast/types.rs b/src/wasm-lib/kcl/src/ast/types.rs index aef5367ca5..48f9c6c1b3 100644 --- a/src/wasm-lib/kcl/src/ast/types.rs +++ b/src/wasm-lib/kcl/src/ast/types.rs @@ -2977,7 +2977,7 @@ impl MemberExpression { source_ranges: vec![self.clone().into()], })), (being_indexed, _) => { - let t = human_friendly_type(being_indexed); + let t = human_friendly_type(&being_indexed); Err(KclError::Semantic(KclErrorDetails { message: format!("Only arrays and objects can be indexed, but you're trying to index a {t}"), source_ranges: vec![self.clone().into()], @@ -4071,7 +4071,7 @@ impl ConstraintLevels { } } -fn human_friendly_type(j: JValue) -> &'static str { +pub(crate) fn human_friendly_type(j: &JValue) -> &'static str { match j { JValue::Null => "null", JValue::Bool(_) => "boolean (true/false value)", diff --git a/src/wasm-lib/kcl/src/executor.rs b/src/wasm-lib/kcl/src/executor.rs index 73224b1595..a5aa8eec30 100644 --- a/src/wasm-lib/kcl/src/executor.rs +++ b/src/wasm-lib/kcl/src/executor.rs @@ -11,7 +11,7 @@ use serde_json::Value as JValue; use tower_lsp::lsp_types::{Position as LspPosition, Range as LspRange}; use crate::{ - ast::types::{BodyItem, Expr, FunctionExpression, KclNone, Program, TagDeclarator}, + ast::types::{human_friendly_type, BodyItem, Expr, FunctionExpression, KclNone, Program, TagDeclarator}, engine::EngineManager, errors::{KclError, KclErrorDetails}, fs::FileManager, @@ -314,16 +314,9 @@ impl KclValue { /// Human readable type name used in error messages. Should not be relied /// on for program logic. - pub(crate) fn display_type_name(&self) -> &'static str { + pub(crate) fn human_friendly_type(&self) -> &'static str { match self { - KclValue::UserVal(u) => match u.value { - JValue::Null => "Null", - JValue::Bool(_) => "Bool", - JValue::Number(_) => "Number", - JValue::String(_) => "String", - JValue::Array(_) => "Array", - JValue::Object(_) => "Object", - }, + KclValue::UserVal(u) => human_friendly_type(&u.value), KclValue::TagDeclarator(_) => "TagDeclarator", KclValue::TagIdentifier(_) => "TagIdentifier", KclValue::SketchGroup(_) => "SketchGroup", diff --git a/src/wasm-lib/kcl/src/std/args.rs b/src/wasm-lib/kcl/src/std/args.rs index f620701a38..1e796a4887 100644 --- a/src/wasm-lib/kcl/src/std/args.rs +++ b/src/wasm-lib/kcl/src/std/args.rs @@ -462,7 +462,7 @@ where message: format!( "Argument at index {i} was supposed to be type {} but found {}", type_name::(), - arg.display_type_name() + arg.human_friendly_type() ), source_ranges: vec![args.source_range], })); @@ -482,7 +482,7 @@ where message: format!( "Argument at index {i} was supposed to be type {} but found {}", type_name::(), - arg.display_type_name() + arg.human_friendly_type() ), source_ranges: vec![args.source_range], })); diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index 62129dd6f8..32fe91e316 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -903,7 +903,7 @@ const part = rectShape([0, 0], 20, 20) assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([887, 936])], message: "Argument at index 0 was supposed to be type [f64; 2] but found String" }"#, + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([887, 936])], message: "Argument at index 0 was supposed to be type [f64; 2] but found string (text)" }"#, ); } @@ -1425,7 +1425,7 @@ const secondSketch = startSketchOn(part001, '') assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([272, 298])], message: "Argument at index 1 was supposed to be type kcl_lib::std::sketch::FaceTag but found String" }"# + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([272, 298])], message: "Argument at index 1 was supposed to be type kcl_lib::std::sketch::FaceTag but found string (text)" }"# ); } @@ -2236,7 +2236,7 @@ someFunction('INVALID') assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([37, 61]), SourceRange([65, 88])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found String" }"# + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([37, 61]), SourceRange([65, 88])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found string (text)" }"# ); } @@ -2257,7 +2257,7 @@ someFunction('INVALID') assert!(result.is_err()); assert_eq!( result.err().unwrap().to_string(), - r#"semantic: KclErrorDetails { source_ranges: [SourceRange([89, 114]), SourceRange([126, 155]), SourceRange([159, 182])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found String" }"# + r#"semantic: KclErrorDetails { source_ranges: [SourceRange([89, 114]), SourceRange([126, 155]), SourceRange([159, 182])], message: "Argument at index 0 was supposed to be type kcl_lib::std::sketch::SketchData but found string (text)" }"# ); }