alibaba/spring-ai-alibaba · error · Exception

Language not recognized in code execution:<language>

Error message

Language not recognized in code execution:<language>

What it means

CodeUtils.getExecutableForLanguage maps a language string to the interpreter executable and throws a checked Exception 'Language not recognized in code execution:<language>' for any language outside its switch (python/python3, shell/bash/sh/powershell, nodejs, java).

Source

Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/utils/CodeUtils.java:31

 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.cloud.ai.graph.utils;

/**
 * @author HeYQ
 * @since 2025-06-01 20:35
 */

public class CodeUtils {

	public static String getExecutableForLanguage(String language) throws Exception {
		return switch (language) {
			case "python3", "python" -> language;
			case "shell", "bash", "sh", "powershell" -> "sh";
			case "nodejs" -> "node";
			case "java" -> "java";
			default -> throw new Exception("Language not recognized in code execution:" + language);
		};
	}

	public static String getFileExtForLanguage(String language) throws Exception {
		return switch (language) {
			case "python3", "python" -> "py";
			case "shell", "bash", "sh", "powershell" -> "sh";
			case "nodejs" -> "js";
			case "java" -> "java";
			default -> throw new Exception("Language not recognized in code execution:" + language);
		};
	}

}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Use a supported language string: python3/python, shell/bash/sh/powershell, nodejs, or java.
  2. Pre-normalize aliases ('js'/'javascript' -> 'nodejs') before calling.
  3. Catch the Exception and reject the code block upstream with a helpful message.
  4. Extend the switch / contribute a new mapping if the language must be supported.

Example fix

// before
String exe = CodeUtils.getExecutableForLanguage("javascript"); // throws
// after
String lang = "javascript".equalsIgnoreCase(lang) ? "nodejs" : lang;
String exe = CodeUtils.getExecutableForLanguage(lang);
Defensive patterns

Strategy: validation

Validate before calling

Set<String> allowed = Set.of("python3","python","shell","bash","sh","powershell","nodejs","java");
if (language == null || !allowed.contains(language.trim().toLowerCase())) {
    throw new IllegalArgumentException("Unsupported language: " + language);
}

Type guard

boolean isSupportedLanguage(String lang) {
    return lang != null && Set.of("python3","python","shell","bash","sh","powershell","nodejs","java").contains(lang.trim().toLowerCase());
}

Try / catch

try {
    exe = CodeUtils.getExecutableForLanguage(language);
} catch (Exception e) {
    throw new IllegalStateException("Cannot execute code: " + e.getMessage() + " — use python/python3/shell/bash/sh/powershell/nodejs/java");
}

Prevention

When it happens

Trigger: Calling getExecutableForLanguage with values like 'javascript', 'py', 'python2', 'golang', or any LLM-emitted language tag not in the supported set.

Common situations: Model emits 'javascript' but the framework expects 'nodejs'; user config uses 'powershell' expecting Windows PowerShell when only sh is used; unsupported languages like go/rust passed programmatically.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/89f1cf5fa053f437. Report an issue: GitHub.