{"record":{"id":"cf07ad57f140d2f6","repo":"alibaba/spring-ai-alibaba","slug":"id","errorCode":null,"errorMessage":"模型缺少 id","messagePattern":"模型缺少 id","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/repository/impl/FileModelConfigRepository.java","lineNumber":116,"sourceCode":"        YamlRoot root = yamlMapper.readValue(bytes, YamlRoot.class);\n        if (root == null || root.models == null) {\n            return new HashMap<>();\n        }\n        \n        Map<Long, ModelConfigDO> map = new HashMap<>();\n        Set<Long> ids = new HashSet<>();\n        Set<String> names = new HashSet<>();\n        for (YamlModel m : root.models) {\n            validateYamlModel(m, ids, names);\n            ModelConfigDO entity = toEntity(m);\n            map.put(entity.getId(), entity);\n        }\n        return map;\n    }\n    \n    private void validateYamlModel(YamlModel m, Set<Long> ids, Set<String> names) {\n        if (m.id == null) {\n            throw new IllegalArgumentException(\"模型缺少 id\");\n        }\n        if (m.name == null || m.name.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 name\");\n        }\n        if (m.provider == null || m.provider.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 provider\");\n        }\n        if (m.modelName == null || m.modelName.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 modelName\");\n        }\n        //        if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException(\"模型缺少 baseUrl\");\n        if (m.apiKey == null || m.apiKey.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 apiKey\");\n        }\n        if (!ids.add(m.id)) {\n            throw new IllegalArgumentException(\"重复的模型 id: \" + m.id);\n        }\n        if (!names.add(m.name)) {","sourceCodeStart":98,"sourceCodeEnd":134,"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/repository/impl/FileModelConfigRepository.java#L98-L134","documentation":"FileModelConfigRepository.validateYamlModel() validates each model entry parsed from the models YAML file and throws IllegalArgumentException \"模型缺少 id\" (\"model missing id\") when the YamlModel's id field is null. Every persisted model must carry a unique Long id, since ids are collected into a duplicate-checking set afterwards.","triggerScenarios":"Loading a models YAML file where a model entry omits the `id` key, or where YAML parsing leaves id null (wrong key name, wrong indentation, or id written as a non-mappable value).","commonSituations":"Hand-editing the YAML and forgetting id on a new model block; copy-pasting a template that has id commented out; YAML indentation mistakes nesting id under the wrong node.","solutions":["Open the models YAML file and add a unique numeric `id` to every model entry.","Check for duplicate ids at the same time — validateYamlModel also rejects ids already present in the ids set.","Verify YAML indentation so `id` sits directly under the model entry, not nested deeper.","Confirm the YamlModel field name matches the YAML key (id) exactly."],"exampleFix":"// before (yaml)\nmodels:\n  - name: qwen\n    provider: dashscope\n// after (yaml)\nmodels:\n  - id: 1\n    name: qwen\n    provider: dashscope","handlingStrategy":"validation","validationCode":"// pre-validate yaml before load\nmodels.forEach(m -> {\n    if (m.id == null) throw new IllegalArgumentException(\"entry '\" + m.name + \"' missing id\");\n    if (ids.contains(m.id)) throw new IllegalArgumentException(\"duplicate id \" + m.id);\n    ids.add(m.id);\n});","typeGuard":"static boolean hasId(YamlModel m) { return m != null && m.id != null; }","tryCatchPattern":"try { repo = FileModelConfigRepository.loadFromFile(path); }\ncatch (IllegalArgumentException e) { log.error(\"Model config invalid: {}\", e.getMessage()); throw new ConfigurationException(e); }","preventionTips":["Lint the models YAML in CI (schema check requiring id/name/provider/modelName/apiKey)","Use a JSON/YAML schema validator before deploying config changes","Keep a commented template entry showing all required fields","Include the entry name in validation messages to locate offenders fast"],"tags":["yaml","validation","configuration","missing-field"],"backgroundTag":"missing-required-config-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"}