Skip to content

Commit

Permalink
fix source range for last command when engine error (#2757)
Browse files Browse the repository at this point in the history
* fix source range for last command

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add known issues

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add a comment

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz authored Jun 22, 2024
1 parent fa37752 commit 3300772
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
9 changes: 8 additions & 1 deletion docs/kcl/KNOWN-ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ once fixed in engine will just start working here with no language changes.
currently move or transform the imported objects at all, once we have assemblies
this will work.

- **Fillets**: Fillets cannot intersect, you will get an error. Only simple fillet cases work currently.
- **Fillets**: Fillets cannot intersect, you will get an error. Only simple fillet
cases work currently.

- **Chamfers**: Chamfers cannot intersect, you will get an error. Only simple
chamfer cases work currently.

- **Shell**: Shell is only working for `end` faces, not for `side` or `start`
faces. We are tracking the engine side bug on this.
2 changes: 1 addition & 1 deletion src/wasm-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/wasm-lib/kcl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "kcl-lib"
description = "KittyCAD Language implementation and tools"
version = "0.1.63"
version = "0.1.64"
edition = "2021"
license = "MIT"
repository = "https://github.com/KittyCAD/modeling-app"
Expand Down
13 changes: 13 additions & 0 deletions src/wasm-lib/kcl/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ pub trait EngineManager: std::fmt::Debug + Send + Sync + 'static {
}
}
WebSocketRequest::ModelingCmdReq { cmd: _, cmd_id } => {
// You are probably wondering why we can't just return the source range we were
// passed with the function. Well this is actually really important.
// If this is the last command in the batch and there is only one and we've reached
// the end of the file, this will trigger a flush batch function, but it will just
// send default or the end of the file as it's source range not the origin of the
// request so we need the original request source range in case the engine returns
// an error.
let source_range = id_to_source_range.get(&cmd_id).cloned().ok_or_else(|| {
KclError::Engine(KclErrorDetails {
message: format!("Failed to get source range for command ID: {:?}", cmd_id),
source_ranges: vec![],
})
})?;
let ws_resp = self
.inner_send_modeling_cmd(cmd_id, source_range, final_req, id_to_source_range)
.await?;
Expand Down
24 changes: 24 additions & 0 deletions src/wasm-lib/tests/executor/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2245,3 +2245,27 @@ const baseExtrusion = extrude(width, sketch001)
1.0,
);
}

#[tokio::test(flavor = "multi_thread")]
async fn serial_test_engine_error_source_range_on_last_command() {
let code = r#"const sketch001 = startSketchOn('XZ')
|> startProfileAt([61.74, 206.13], %)
|> xLine(305.11, %, 'seg01')
|> yLine(-291.85, %)
|> xLine(-segLen('seg01', %), %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
|> extrude(40.14, %)
|> shell({
faces: ["seg01"],
thickness: 3.14,
}, %)
"#;

let result = execute_and_snapshot(code, UnitLength::Mm).await;
assert!(result.is_err());
assert_eq!(
result.err().unwrap().to_string(),
r#"engine: KclErrorDetails { source_ranges: [SourceRange([262, 320])], message: "Modeling command failed: [ApiError { error_code: InternalEngine, message: \"Invalid brep after shell operation\" }]" }"#
);
}

0 comments on commit 3300772

Please sign in to comment.