{"record":{"id":"8abb6929c69ec011","repo":"alibaba/spring-ai-alibaba","slug":"error-8abb69","errorCode":null,"errorMessage":"模型配置格式错误: ","messagePattern":"模型配置格式错误: ","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/utils/ModelConfigParser.java","lineNumber":45,"sourceCode":"    \n    private final ModelManager modelManager;\n    \n    /**\n     * 解析模型配置JSON字符串\n     *\n     * @param modelConfigJson 模型配置JSON\n     * @return 模型配置信息\n     */\n    public ModelConfigInfo parseModelConfig(String modelConfigJson) {\n        if (!StringUtils.hasText(modelConfigJson)) {\n            throw new IllegalArgumentException(\"模型配置不能为空\");\n        }\n        \n        try {\n            return objectMapper.readValue(modelConfigJson, ModelConfigInfo.class);\n        } catch (Exception e) {\n            log.error(\"解析模型配置JSON失败: {}\", modelConfigJson, e);\n            throw new IllegalArgumentException(\"模型配置格式错误: \" + e.getMessage(), e);\n        }\n    }\n    \n    public ModelConfigInfo checkAndGetModelConfigInfo(String modelConfig) {\n        ModelConfigInfo modelConfigInfo = null;\n        try {\n            modelConfigInfo = parseModelConfig(modelConfig);\n            validateModelConfig(modelConfigInfo);\n            \n            // 验证模型配置是否存在\n            // 首先尝试从 ModelConfigRepository (YAML 文件) 查找\n            boolean exists = modelConfigRepository.existsById(modelConfigInfo.getModelId());\n            \n            if (!exists) {\n                // 如果 ModelConfigRepository 中不存在，尝试从 ModelManager (数据库) 查找\n                // 安全地获取 workspaceId\n                String workspaceId = null;\n                try {","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/utils/ModelConfigParser.java#L27-L63","documentation":"An IllegalArgumentException thrown by ModelConfigParser.parseModelConfig when Jackson (objectMapper.readValue) cannot deserialize modelConfigJson into ModelConfigInfo. The original exception is logged and wrapped, so the message carries Jackson's reason (syntax error, unknown fields failing, type mismatch, etc.).","triggerScenarios":"Calling parseModelConfig with a string that is not valid JSON (truncated, HTML error page, single quotes, trailing comma) or valid JSON whose shape doesn't match ModelConfigInfo (e.g. modelId as an object instead of string).","commonSituations":"Hand-edited config stored in the DB; config produced by a different tool/version with a different schema; encoding issues corrupting the stored JSON; copy-paste errors including markdown fences.","solutions":["Validate the JSON with a linter/parser before storing or passing it (e.g. objectMapper.readTree in a pre-check).","Fix the JSON syntax so it parses (check the wrapped e.getMessage() for line/column).","Compare the JSON keys/types against ModelConfigInfo fields and align them.","Re-save the model config through the official UI/API so it is serialized by the same ObjectMapper."],"exampleFix":"// before\nString cfg = \"{modelId: 'qwen-max'}\"; // invalid JSON\nModelConfigInfo info = parser.parseModelConfig(cfg);\n// after\nString cfg = \"{\\\"modelId\\\":\\\"qwen-max\\\"}\";\nModelConfigInfo info = parser.parseModelConfig(cfg);","handlingStrategy":"validation","validationCode":"try { new ObjectMapper().readTree(cfg); } catch (Exception e) { throw new BadRequestException(\"modelConfig is not valid JSON: \" + e.getMessage()); }","typeGuard":"null","tryCatchPattern":"try { return parser.parseModelConfig(cfg); } catch (IllegalArgumentException e) { throw new BadRequestException(\"Invalid modelConfig JSON: \" + e.getMessage()); }","preventionTips":["Validate JSON before persisting configs","Only edit configs through the official editor/API","Check the wrapped cause message for the exact parse error position"],"tags":["json","model-config","parse-error"],"backgroundTag":"json-parse-error","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"}