{"record":{"id":"326cf7c170524421","repo":"alibaba/spring-ai-alibaba","slug":"type-requires-name-field","errorCode":null,"errorMessage":"${type} requires 'name' field","messagePattern":"(.+?) requires 'name' field","errorType":"validation","errorClass":"IllegalArgumentException","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/agent/AbstractAgentTypeProvider.java","lineNumber":45,"sourceCode":" * @author yHong\n * @version 1.0\n * @since 2025/9/8 18:31\n */\npublic abstract class AbstractAgentTypeProvider implements AgentTypeProvider {\n\n\t/**\n\t * 提供默认的校验实现，子类可以重写以添加特定的校验逻辑\n\t */\n\t@Override\n\tpublic void validateDSL(Map<String, Object> root) {\n\t\t// 基础校验：检查必需字段\n\t\tif (root == null) {\n\t\t\tthrow new IllegalArgumentException(type() + \" requires valid configuration\");\n\t\t}\n\n\t\tString name = (String) root.get(\"name\");\n\t\tif (isBlank(name)) {\n\t\t\tthrow new IllegalArgumentException(type() + \" requires 'name' field\");\n\t\t}\n\n\t\t// 调用子类特定的校验逻辑\n\t\tvalidateSpecific(root);\n\t}\n\n\t/**\n\t * 子类实现特定的校验逻辑\n\t * @param root DSL 根对象\n\t */\n\tprotected abstract void validateSpecific(Map<String, Object> root);\n\n\t/**\n\t * 校验 handle 是否存在\n\t * @param root DSL 根对象\n\t * @return handle Map\n\t */\n\t@SuppressWarnings(\"unchecked\")","sourceCodeStart":27,"sourceCodeEnd":63,"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/agent/AbstractAgentTypeProvider.java#L27-L63","documentation":"AbstractAgentTypeProvider.validateDSL() throws this IllegalArgumentException when the agent DSL configuration object exists but has no 'name' field. Every agent definition in the DSL must carry a name; it is used as the generated class/agent identity. This is a fail-fast schema validation before any code generation happens.","triggerScenarios":"Calling the agent project generator (via validateDSL) with a config map like {\"type\":\"react_agent\", ...} that omits \"name\", or where \"name\" is an empty/whitespace string (isBlank check).","commonSituations":"Hand-written DSL JSON/YAML missing the name key; a UI builder exporting a partial draft; renaming a field to \"agentName\" or \"title\" in custom tooling; programmatic map construction that skips optional-looking fields.","solutions":["Add a non-blank \"name\" field to the agent configuration root object","Check the JSON/YAML source for the agent definition and ensure name is present and non-empty","If generating configs programmatically, validate that name is set before invoking the generator"],"exampleFix":"// before\n{\"type\": \"react_agent\", \"handle\": {\"model\": \"qwen-max\"}}\n// after\n{\"type\": \"react_agent\", \"name\": \"my-react-agent\", \"handle\": {\"model\": \"qwen-max\"}}","handlingStrategy":"validation","validationCode":"if (config == null || isBlank((String) config.get(\"name\"))) {\n    throw new IllegalArgumentException(\"agent config requires a non-blank 'name' field\");\n}","typeGuard":"static boolean hasName(Map<String,Object> cfg) {\n    return cfg.get(\"name\") instanceof String s && !s.isBlank();\n}","tryCatchPattern":"try {\n    generator.generate(description);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"requires 'name' field\")) {\n        // surface a field-level error to the user pointing at the name key\n    }\n}","preventionTips":["Always include \"name\" as the first field in agent DSL definitions","Add a JSON/YAML schema check with required:[name] before submitting configs","Validate configs in your form/UI before export"],"tags":["validation","dsl","config"],"backgroundTag":"empty-required-field","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"}