From 9730e3f5b32c087c2d21dbf6000e5eb89cadca89 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Tue, 22 Apr 2025 15:24:53 -0500 Subject: [PATCH] KCL: Rephrase confusing error msg (#6436) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: × undefined value: memory item key `foo` is not defined Now: × undefined value: `foo` is not defined --- e2e/playwright/sketch-tests.spec.ts | 2 +- rust/kcl-lib/src/execution/memory.rs | 4 ++-- rust/kcl-lib/src/execution/mod.rs | 4 ++-- rust/kcl-lib/tests/cube_with_error/execution_error.snap | 2 +- src/lang/executor.test.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/e2e/playwright/sketch-tests.spec.ts b/e2e/playwright/sketch-tests.spec.ts index 9b0822c47..d25eca3a6 100644 --- a/e2e/playwright/sketch-tests.spec.ts +++ b/e2e/playwright/sketch-tests.spec.ts @@ -3295,7 +3295,7 @@ profile003 = startProfileAt([-201.08, 254.17], sketch002) ) await editor.expectState({ activeLines: [], - diagnostics: ['memoryitemkey`badBadBadFn`isnotdefined'], + diagnostics: ['`badBadBadFn`isnotdefined'], highlightedCode: '', }) await expect( diff --git a/rust/kcl-lib/src/execution/memory.rs b/rust/kcl-lib/src/execution/memory.rs index a1d7c330a..484d4173f 100644 --- a/rust/kcl-lib/src/execution/memory.rs +++ b/rust/kcl-lib/src/execution/memory.rs @@ -365,7 +365,7 @@ impl ProgramMemory { } Err(KclError::UndefinedValue(KclErrorDetails { - message: format!("memory item key `{}` is not defined", var), + message: format!("`{}` is not defined", var), source_ranges: vec![source_range], })) } @@ -486,7 +486,7 @@ impl ProgramMemory { } Err(KclError::UndefinedValue(KclErrorDetails { - message: format!("memory item key `{}` is not defined", var), + message: format!("`{}` is not defined", var), source_ranges: vec![], })) } diff --git a/rust/kcl-lib/src/execution/mod.rs b/rust/kcl-lib/src/execution/mod.rs index 11a1556d1..e5b409c27 100644 --- a/rust/kcl-lib/src/execution/mod.rs +++ b/rust/kcl-lib/src/execution/mod.rs @@ -1585,7 +1585,7 @@ const answer = returnX()"#; assert_eq!( err, KclError::UndefinedValue(KclErrorDetails { - message: "memory item key `x` is not defined".to_owned(), + message: "`x` is not defined".to_owned(), source_ranges: vec![ SourceRange::new(64, 65, ModuleId::default()), SourceRange::new(97, 106, ModuleId::default()) @@ -1669,7 +1669,7 @@ let shape = layer() |> patternTransform(instances = 10, transform = transform) assert_eq!( err, KclError::UndefinedValue(KclErrorDetails { - message: "memory item key `x` is not defined".to_owned(), + message: "`x` is not defined".to_owned(), source_ranges: vec![SourceRange::new(80, 81, ModuleId::default())], }), ); diff --git a/rust/kcl-lib/tests/cube_with_error/execution_error.snap b/rust/kcl-lib/tests/cube_with_error/execution_error.snap index 4e7479577..820c916dd 100644 --- a/rust/kcl-lib/tests/cube_with_error/execution_error.snap +++ b/rust/kcl-lib/tests/cube_with_error/execution_error.snap @@ -4,7 +4,7 @@ description: Error from executing cube_with_error.kcl --- KCL UndefinedValue error - × undefined value: memory item key `foo` is not defined + × undefined value: `foo` is not defined ╭─[23:1] 22 │ // Error, after creating meaningful output. 23 │ foo diff --git a/src/lang/executor.test.ts b/src/lang/executor.test.ts index 7e855f142..c4c6ee824 100644 --- a/src/lang/executor.test.ts +++ b/src/lang/executor.test.ts @@ -462,7 +462,7 @@ const theExtrude = startSketchOn(XY) await expect(exe(code)).rejects.toEqual( new KCLError( 'undefined_value', - 'memory item key `myVarZ` is not defined', + '`myVarZ` is not defined', topLevelRange(129, 135), [], [],