KCL: Fix cryptic error when using duplicate edges in fillet call (#5755)

Fixes https://github.com/KittyCAD/modeling-app/issues/4307

Now if you try to fillet the same edge twice in a single fillet command,
the error message is clearer, and the source range will highlight
the specific edges in the array which are duplicated.

Same goes for chamfer.

Note: although the Rust KCL interpreter sends back an array of SourceRange
for each KCL error, the frontend only puts the first one into CodeMirror
diagnostics. We should fix that: https://github.com/KittyCAD/modeling-app/issues/5754
This commit is contained in:
Adam Chalmers
2025-03-12 11:24:27 -05:00
committed by GitHub
parent f8e53c6577
commit 865bf8ae7a
7 changed files with 125 additions and 49 deletions

View File

@ -1,8 +1,15 @@
const part001 = startSketchOn('XY')
|> startProfileAt([0,0], %)
|> line(end = [0, 10], tag = $thing)
|> line(end = [10, 0])
|> line(end = [0, -10], tag = $thing2)
|> close()
|> extrude(length = 10)
|> fillet(radius = 0.5, tags = [thing, thing])
startProfileAt([0, 0], startSketchOn("XY"))
|> xLine(length = 10, tag = $line000)
|> yLine(length = 10, tag = $line001)
|> xLine(endAbsolute = profileStartX(%), tag = $line002)
|> close(tag = $line003)
|> extrude(length = 10)
|> fillet(
radius = 1,
tags = [
line003,
getNextAdjacentEdge(line000),
getPreviousAdjacentEdge(line001)
],
)

View File

@ -27,11 +27,14 @@ async fn kcl_test_fillet_duplicate_tags() {
let code = kcl_input!("fillet_duplicate_tags");
let result = execute_and_snapshot(code, UnitLength::Mm, None).await;
assert!(result.is_err());
let err = result.expect_err("Code should have failed due to the duplicate edges being filletted");
let err = err.as_kcl_error().unwrap();
assert_eq!(
result.err().unwrap().to_string(),
r#"type: KclErrorDetails { source_ranges: [SourceRange([229, 272, 0])], message: "Duplicate tags are not allowed." }"#,
err.message(),
"The same edge ID is being referenced multiple times, which is not allowed. Please select a different edge"
);
assert_eq!(err.source_ranges().len(), 2);
}
#[tokio::test(flavor = "multi_thread")]