alibaba/spring-ai-alibaba · error · RuntimeException
unexcepted result
Error message
unexcepted result
What it means
In generated CodeNode helper code (assistMethodCode), after executing the code node action, the runtime unpacks the result for the expected key and requires it to be a Map whose entries are re-keyed as '<nodeName>_<key>'. If the value is missing or not a Map, this RuntimeException('unexcepted result') is thrown (note the typo in the message).
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/generator/service/generator/workflow/sections/CodeNodeSection.java:93
tempDir.toFile().deleteOnExit();
codeExecutionConfig = new CodeExecutionConfig().setWorkDir(tempDir.toString());
codeExecutor = new LocalCommandlineCodeExecutor();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private NodeAction wrapperCodeNodeAction(NodeAction codeNodeAction, String key,
String nodeName, int maxRetryCount, int retryIntervalMs, Map<String, Object> defaultValue) {
return state -> {
int count = maxRetryCount;
while (count-- > 0) {
try {
// 将代码运行的结果拆包
Map<String, Object> result = codeNodeAction.apply(state);
Object object = result.get(key);
if(!(object instanceof Map)) {
throw new RuntimeException("unexcepted result");
}
return ((Map<String, Object>) object).entrySet().stream()
.collect(Collectors.toMap(
entry -> nodeName + "_" + entry.getKey(),
Map.Entry::getValue
));
} catch (Exception e) {
Thread.sleep(retryIntervalMs);
}
}
if(defaultValue != null) {
return defaultValue;
} else {
throw new RuntimeException("code execution failed!");
}
};
}
""";View on GitHub (pinned to f82da0b50f)
Solutions
- Make the code node return a Map with the expected output key, e.g. return {'result': {...}}.
- Verify the output key configured on the node matches a key in the script's returned Map.
- If the result can legitimately be non-Map, adjust the script to wrap it in a Map before returning.
Example fix
// before (code node script)
return result; // plain list
// after
return Map.of("output", result); // return a Map under the expected key Defensive patterns
Strategy: type-guard
Validate before calling
Object out = scriptOutput.get(expectedKey);
if (!(out instanceof Map)) throw new IllegalArgumentException("Code node must return a Map under key " + expectedKey); Type guard
boolean isMapResult(Map<String,Object> state, String key) { return state.get(key) instanceof Map; } Try / catch
try { Function<Map<String,Object>,Map<String,Object>> fn = buildCodeNode(cfg); return fn.apply(state); } catch (RuntimeException e) { if ("unexcepted result".equals(e.getMessage())) { /* fix script return shape */ } throw e; } Prevention
- Always return a Map from code node scripts with the configured output key
- Keep the output key in node config in sync with the script's return keys
- Unit-test code node scripts against the expected state shape
When it happens
Trigger: Generated code node action returns a state in which result.get(key) is null or a non-Map object (e.g. List, String, number), then the retry loop exhausts and this error surfaces.
Common situations: User-written code node script returns a plain value or list instead of a Map under the expected output key; output key renamed in the node config; script partially rewritten and drops the required return shape.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- INVALID_PARAMS
- WORKFLOW_CONFIG_INVALID
- code execution failed!
- value {${arrayKey}} is not an array!
- unknown component type: + componentType.getValue()
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/26a6abad15425a92.
Report an issue: GitHub.