alibaba/spring-ai-alibaba · error · IllegalArgumentException

No enum constant com.alibaba.cloud.ai.graph.node.code.entity

Error message

No enum constant com.alibaba.cloud.ai.graph.node.code.entity.CodeLanguage.<value>

What it means

CodeLanguage.fromValue throws IllegalArgumentException('No enum constant ...CodeLanguage.<value>') when the string is non-blank but matches no known language value (case-insensitively). The full enum class name plus offending value is embedded in the message.

Source

Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/entity/CodeLanguage.java:46

	CodeLanguage(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;
	}

	// Optionally, you can add a method to find an enum constant by its string value
	public static CodeLanguage fromValue(String value) {
		if (value == null || value.trim().isEmpty()) {
			throw new IllegalArgumentException("Invalid code language provided");
		}
		for (CodeLanguage lang : values()) {
			if (lang.getValue().equalsIgnoreCase(value)) {
				return lang;
			}
		}
		throw new IllegalArgumentException("No enum constant " + CodeLanguage.class.getName() + "." + value);
	}

	@Override
	public String toString() {
		return this.value;
	}

}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Check the supported values via CodeLanguage.values() and use an exact registered one (python/python3/shell/bash/nodejs/java etc.).
  2. Normalize/trim the input string before conversion.
  3. Add a mapping layer for common aliases (js -> nodejs) before calling fromValue.
  4. Catch IllegalArgumentException and fall back to a default language.

Example fix

// before
CodeLanguage lang = CodeLanguage.fromValue("javascript"); // IllegalArgumentException
// after
String language = "javascript".trim();
if (language.equalsIgnoreCase("js") || language.equalsIgnoreCase("javascript")) language = "nodejs";
CodeLanguage lang = CodeLanguage.fromValue(language);
Defensive patterns

Strategy: validation

Validate before calling

Set<String> supported = Arrays.stream(CodeLanguage.values()).map(CodeLanguage::getValue).collect(Collectors.toSet());
if (!supported.contains(rawLanguage.trim().toLowerCase())) {
    throw new IllegalArgumentException("Unsupported language: " + rawLanguage + ", supported: " + supported);
}

Type guard

boolean isKnownCodeLanguage(String lang) {
    if (lang == null) return false;
    return Arrays.stream(CodeLanguage.values()).anyMatch(l -> l.getValue().equalsIgnoreCase(lang.trim()));
}

Try / catch

try {
    return CodeLanguage.fromValue(rawLanguage);
} catch (IllegalArgumentException e) {
    log.error("Unknown code language '{}' — must be one of the CodeLanguage values", rawLanguage);
    throw new IllegalArgumentException("Unsupported language: " + rawLanguage, e);
}

Prevention

When it happens

Trigger: Calling CodeLanguage.fromValue("py") or "javascript" or "Python3." — any alias not exactly equal (ignoring case) to a registered value like python/python3/shell/bash/nodejs/java.

Common situations: Users writing common aliases ('js', 'python3.x', 'powershell', 'golang') in config; LLM emitting 'javascript' for a 'nodejs'-only enum; copy-pasting language names with trailing whitespace/quotes.

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/750c5c80113c9688. Report an issue: GitHub.