{"record":{"id":"26a6abad15425a92","repo":"alibaba/spring-ai-alibaba","slug":"unexcepted-result","errorCode":null,"errorMessage":"unexcepted result","messagePattern":"unexcepted result","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"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","lineNumber":93,"sourceCode":"\t\t\t\t\t\t           tempDir.toFile().deleteOnExit();\n\t\t\t\t\t\t           codeExecutionConfig = new CodeExecutionConfig().setWorkDir(tempDir.toString());\n\t\t\t\t\t\t           codeExecutor = new LocalCommandlineCodeExecutor();\n\t\t\t\t\t\t       } catch (Exception e) {\n\t\t\t\t\t\t           throw new RuntimeException(e);\n\t\t\t\t\t\t       }\n\t\t\t\t\t\t   }\n\n\t\t\t\t\t\t   private NodeAction wrapperCodeNodeAction(NodeAction codeNodeAction, String key,\n\t\t\t\t\t\t                    String nodeName, int maxRetryCount, int retryIntervalMs, Map<String, Object> defaultValue) {\n\t\t\t\t\t\t       return state -> {\n\t\t\t\t\t\t           int count = maxRetryCount;\n\t\t\t\t\t\t           while (count-- > 0) {\n\t\t\t\t\t\t               try {\n\t\t\t\t\t\t                   // 将代码运行的结果拆包\n\t\t\t\t\t\t                   Map<String, Object> result = codeNodeAction.apply(state);\n\t\t\t\t\t\t                   Object object = result.get(key);\n\t\t\t\t\t\t                   if(!(object instanceof Map)) {\n\t\t\t\t\t\t                       throw new RuntimeException(\"unexcepted result\");\n\t\t\t\t\t\t                   }\n\t\t\t\t\t\t                   return ((Map<String, Object>) object).entrySet().stream()\n\t\t\t\t\t\t                           .collect(Collectors.toMap(\n\t\t\t\t\t\t                                   entry -> nodeName + \"_\" + entry.getKey(),\n\t\t\t\t\t\t                                   Map.Entry::getValue\n\t\t\t\t\t\t                           ));\n\t\t\t\t\t\t               } catch (Exception e) {\n\t\t\t\t\t\t                   Thread.sleep(retryIntervalMs);\n\t\t\t\t\t\t               }\n\t\t\t\t\t\t           }\n\t\t\t\t\t\t           if(defaultValue != null) {\n\t\t\t\t\t\t               return defaultValue;\n\t\t\t\t\t\t           } else {\n\t\t\t\t\t\t               throw new RuntimeException(\"code execution failed!\");\n\t\t\t\t\t\t           }\n\t\t\t\t\t\t       };\n\t\t\t\t\t\t   }\n\t\t\t\t\t\t\"\"\";","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/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#L75-L111","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (code node script)\nreturn result;  // plain list\n// after\nreturn Map.of(\"output\", result); // return a Map under the expected key","handlingStrategy":"type-guard","validationCode":"Object out = scriptOutput.get(expectedKey);\nif (!(out instanceof Map)) throw new IllegalArgumentException(\"Code node must return a Map under key \" + expectedKey);","typeGuard":"boolean isMapResult(Map<String,Object> state, String key) { return state.get(key) instanceof Map; }","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["code-node","type-mismatch","workflow"],"backgroundTag":"type-mismatch","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}