Skip to content

Refactor: Improve RunCode.luau for proper output and error handling #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2025

Conversation

waefrebeorn
Copy link
Owner

This commit refactors plugin/src/Tools/RunCode.luau to:

  • Correctly parse the command from the input arguments.
  • Capture output from print, warn, error, and return values from the executed code into a single string.
  • Track whether an error occurred during loadstring or code execution.
  • Return a Lua table that conforms to the CallToolResult structure expected by Main.server.luau (i.e., { content = {{ text = output, type = "text" }}, isError = flag }).
  • Enhances safety of code execution by wrapping chunk() in a pcall and handling loadstring errors.
  • Simplifies internal serialization for constructing the output string.

This makes the code execution more robust and ensures its results and errors are correctly propagated.

google-labs-jules bot and others added 2 commits June 15, 2025 08:09
This commit refactors `plugin/src/Tools/RunCode.luau` to:
- Correctly parse the `command` from the input arguments.
- Capture output from `print`, `warn`, `error`, and return values
  from the executed code into a single string.
- Track whether an error occurred during `loadstring` or code execution.
- Return a Lua table that conforms to the `CallToolResult` structure
  expected by `Main.server.luau` (i.e.,
  `{ content = {{ text = output, type = "text" }}, isError = flag }`).
- Enhances safety of code execution by wrapping `chunk()` in a `pcall`
  and handling `loadstring` errors.
- Simplifies internal serialization for constructing the output string.

This makes the code execution more robust and ensures its results and
errors are correctly propagated.
@waefrebeorn waefrebeorn merged commit 4c5edd7 into main Jun 15, 2025
@waefrebeorn waefrebeorn deleted the fix-luau-plugin-issues branch June 15, 2025 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant