Files
modeling-app/rust
Adam Chalmers b47b9c9613 KCL: Emit proper errors in unexpected edge cases (#7351)
There's some bug in the frontend or KCL somewhere, which results in the TypeScript frontend sending an AST (serialized to JSON) to the KCL executor, but the JSON cannot be deserialized into an AST. If this happens, it's a bug in ZDS, not a user error. 

The problem is that this sort of error will cause the frontend to silently stop rendering KCL, and it won't show the user any errors. They need to open up the console and look at the error there, and even if they do, it's hard to understand.

This PR changes how we report these unexpected errors due to bugs in ZDS. ZDS should not silently stop working, it should at least print a half-decent error like this:

<img width="527" alt="nicer error" src="https://github.com/user-attachments/assets/1bb37a64-0915-4472-849c-d146f397356b" />

## Fix

Right now, the wasm library exports a function `execute`. It previous returned an error as a String if one occurred. The frontend assumed this error string would be JSON that matched the schema `KclErrorWithOutputs`. This was not always true! For example, if something couldn't be serialized to JSON, we'd take the raw Serde error and stringify that. It wouldn't match `KclErrorWithOutputs`.

Now I've changed `execute` so that if it errors, it'll returns a JsValue not a string. So that's one check (can this string be deserialized into a JSON object) that can be removed -- it'll return a JSON object directly now. The next check is "does this JSON object conform to the KclErrorWithOutputs schema". To prove that's correct, I changed `execute` to be a thin wrapper around `fn execute_typed` which returns `Result<ExecOutcome, KclErrorWithOutputs>`. Now we know the error will be the right type.
2025-06-03 15:37:17 -05:00
..
2025-03-13 23:38:41 -07:00
2025-05-30 13:48:17 -04:00
2025-05-30 13:48:17 -04:00
2025-05-30 13:48:17 -04:00
2025-03-04 22:21:12 -08:00

Rust Crates

Releasing

  1. Make sure your working directory is this directory.
  2. Bump the versions of the crates:
    just bump-kcl-crate-versions 
    
  3. Commit the changes:
    git add .
    git commit -m "Bump versions"
    
  4. Push the changes and get your PR approved.
  5. Publish the crates:
    just publish-kcl {version}
    
    • This will publish the relevant crates and push a new tag with the prefix kcl-. DO NOT SET THE PREFIX TO kcl- when you run the command. The just command will do that for you.
    • The tag will then trigger the release of kcl-python-bindings and kcl-language-server.