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 supported language name to its executable command (python, sh, node, java). Any language string outside the fixed switch set throws a plain Exception with the unrecognized language appended to the message.

Source

Thrown at spring-ai-alibaba-graph-core/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 one of the exact supported identifiers: python3, python, shell, bash, sh, powershell, nodejs, java.
  2. Normalize the language string to lowercase and trim whitespace before calling.
  3. Map aliases yourself before the call (e.g. javascript -> nodejs, py -> python).
  4. Extend the switch in CodeUtils if a new language must be supported upstream.

Example fix

// before
String exe = CodeUtils.getExecutableForLanguage(lang); // lang = "JavaScript"
// after
String normalized = lang == null ? "" : lang.trim().toLowerCase();
if (normalized.equals("javascript")) { normalized = "nodejs"; }
String exe = CodeUtils.getExecutableForLanguage(normalized);
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> SUPPORTED = Set.of("python3","python","shell","bash","sh","powershell","nodejs","java");
boolean ok = lang != null && SUPPORTED.contains(lang.trim().toLowerCase());

Type guard

static boolean isSupportedLanguage(String lang) {
    return lang != null && SUPPORTED_LANGUAGES.contains(lang.trim().toLowerCase());
}

Try / catch

try {
    String exe = CodeUtils.getExecutableForLanguage(lang);
} catch (Exception e) {
    throw new IllegalArgumentException("Unsupported language: " + lang + "; supported: python, shell, nodejs, java");
}

Prevention

When it happens

Trigger: Calling getExecutableForLanguage with any string not exactly equal to python3/python/shell/bash/sh/powershell/nodejs/java — e.g. 'py', 'javascript', 'Python' (case-sensitive), 'node', 'pwsh'.

Common situations: Model/LLM emits a language name in slightly different casing or an alias ('javascript' instead of 'nodejs'), user config uses a wrong language identifier in a code-execution node, or a typo in workflow configuration.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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