Stronger types and better error handling in executeMock (#7370)

This brings the `execute_mock` function into line with the `execute` function, which I tweaked in https://github.com/KittyCAD/modeling-app/pull/7351. Now mock execution, like real execution, will always return a properly-formatted KCL error, instead of any possible JS value.

Also, incidentally, I noticed that send_response always succeeds, so I changed it from Result<()> to void.
This commit is contained in:
Adam Chalmers
2025-06-04 17:24:24 -05:00
committed by GitHub
parent 4502ad62b2
commit c25dfabc94
3 changed files with 55 additions and 31 deletions

View File

@ -80,12 +80,12 @@ impl ResponseContext {
}
// Add a response to the context.
pub async fn send_response(&self, data: js_sys::Uint8Array) -> Result<(), JsValue> {
pub async fn send_response(&self, data: js_sys::Uint8Array) {
let ws_result: WebSocketResponse = match bson::from_slice(&data.to_vec()) {
Ok(res) => res,
Err(_) => {
// We don't care about the error if we can't parse it.
return Ok(());
return;
}
};
@ -96,13 +96,11 @@ impl ResponseContext {
let Some(id) = id else {
// We only care if we have an id.
return Ok(());
return;
};
// Add this response to our responses.
self.add(id, ws_result.clone()).await;
Ok(())
}
}

View File

@ -220,6 +220,7 @@ impl schemars::JsonSchema for TypedPath {
///
/// * Does **not** touch `..` or symlinks call `canonicalize()` if you need that.
/// * Returns an owned `PathBuf` only when normalisation was required.
#[cfg(not(target_arch = "wasm32"))]
fn normalise_import<S: AsRef<str>>(raw: S) -> std::path::PathBuf {
let s = raw.as_ref();
// On Unix we need to swap `\` → `/`. On Windows we leave it alone.