Skip to content

fix: raise clear error on unsupported language in execute_code#38448

Merged
crazywoola merged 5 commits into
langgenius:mainfrom
isheng-eqi:fix/code-executor-unsupported-language-guard
Jul 8, 2026
Merged

fix: raise clear error on unsupported language in execute_code#38448
crazywoola merged 5 commits into
langgenius:mainfrom
isheng-eqi:fix/code-executor-unsupported-language-guard

Conversation

@isheng-eqi

Copy link
Copy Markdown
Contributor

Summary

Fixes #37874

Problem

CodeExecutor.execute_code() maps CodeLanguage to sandbox runtime via code_language_to_running_language.get(language). When the language is unsupported, .get() returns None and the request is sent with "language": null, which leads to a cryptic remote sandbox error instead of a clear local failure.

execute_workflow_code_template() already fails fast with CodeExecutionError("Unsupported language ...") when no transformer exists, but execute_code itself has no equivalent guard.

Fix

Add an explicit guard at the start of execute_code():

running_language = cls.code_language_to_running_language.get(language)
if running_language is None:
    raise CodeExecutionError(f"Unsupported language {language}")

Then use the validated running_language in the sandbox request data.

Changes

  • api/core/helper/code_executor/code_executor.py: Add unsupported language guard (5 lines added, 1 changed)

Mathes the existing pattern in execute_workflow_code_template (line 145-146).

execute_code() uses code_language_to_running_language.get(language)
which returns None for unsupported languages. This None gets
serialized as null in the sandbox request, producing a cryptic
remote error instead of a clear local failure.

Add an explicit guard that raises CodeExecutionError with an
'Unsupported language' message before calling the sandbox service.
This matches the pattern already used in execute_workflow_code_template
which has the same guard for unsupported template transformers.

Fixes langgenius#37874
@isheng-eqi isheng-eqi requested a review from QuantumGhost as a code owner July 6, 2026 03:49
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.39% 52.39% 0.00%
Strict coverage 51.90% 51.90% 0.00%
Typed symbols 32,120 32,120 0
Untyped symbols 29,465 29,465 0
Modules 2974 2974 0

@autofix-ci autofix-ci Bot requested review from crazywoola and laipz8200 as code owners July 6, 2026 08:17
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jul 6, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Jul 6, 2026
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 6, 2026
@github-actions github-actions Bot removed the web This relates to changes on the web. label Jul 6, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 8, 2026
@crazywoola crazywoola added this pull request to the merge queue Jul 8, 2026
Merged via the queue into langgenius:main with commit af4538e Jul 8, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CodeExecutor.execute_code sends null language to sandbox for unsupported languages

2 participants