{"record":{"id":"6b005795eb4eabf8","repo":"alibaba/spring-ai-alibaba","slug":"invalid-nacos-config-reference-format-nacosref","errorCode":null,"errorMessage":"Invalid Nacos config reference format: <nacosRef>. Expected format: dataId/group","messagePattern":"Invalid Nacos config reference format: <nacosRef>\\. Expected format: dataId/group","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/tools/NacosMcpGatewayToolCallback.java","lineNumber":150,"sourceCode":"\t\treturn result.toString();\n\t}\n\n\t/**\n\t * 解析Nacos引用\n\t * @param nacosRef 引用字符串，格式为 dataId/group\n\t * @param dotNotation 点语法部分，格式为 .key1.key2（可能为null）\n\t * @return 解析后的值\n\t */\n\tprivate String resolveNacosReference(String nacosRef, String dotNotation) {\n\t\tif (!org.springframework.util.StringUtils.hasText(nacosRef)) {\n\t\t\treturn null;\n\t\t}\n\n\t\ttry {\n\t\t\t// 解析dataId和group\n\t\t\tString[] configParts = nacosRef.split(\"/\");\n\t\t\tif (configParts.length != 2) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"Invalid Nacos config reference format: \" + nacosRef + \". Expected format: dataId/group\");\n\t\t\t}\n\n\t\t\tString dataId = configParts[0];\n\t\t\tString group = configParts[1];\n\n\t\t\t// 获取配置内容\n\t\t\tString configContent = getConfigContent(dataId, group);\n\t\t\tif (!org.springframework.util.StringUtils.hasText(configContent)) {\n\t\t\t\tlogger.warn(\"[resolveNacosReference] No content found for dataId: {}, group: {}\", dataId, group);\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\t// 如果没有点语法，直接返回配置内容\n\t\t\tif (!org.springframework.util.StringUtils.hasText(dotNotation)) {\n\t\t\t\treturn configContent;\n\t\t\t}\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-config-nacos/src/main/java/com/alibaba/cloud/ai/agent/nacos/tools/NacosMcpGatewayToolCallback.java#L132-L168","documentation":"Thrown by NacosMcpGatewayToolCallback.resolveNacosReference when a placeholder value referencing a Nacos config is not in the required 'dataId/group' form (splitting on '/' must yield exactly two parts). It is an IllegalArgumentException indicating a malformed configuration expression in tool input or template.","triggerScenarios":"A ${...} placeholder or nacosRef string containing zero or multiple '/' characters — e.g. 'myDataId' (missing group), 'dataId/group/extra', or 'a/b/c' — reaches resolveNacosReference during template replacement.","commonSituations":"Typos in Nacos references written into prompt/tool templates; groups or dataIds that themselves contain '/' characters; copying examples with the wrong separator.","solutions":["Fix the reference string so it is exactly 'dataId/group' with one slash, e.g. 'my-service-config/DEFAULT_GROUP'.","If the group is DEFAULT_GROUP, write it explicitly rather than omitting it.","If the dataId contains slashes, use an escape/reference format supported by the library instead of a raw slash.","Validate all placeholder values in templates before invoking the tool."],"exampleFix":"// before\nString ref = \"user-service-config\"; // missing group\n// after\nString ref = \"user-service-config/DEFAULT_GROUP\";","handlingStrategy":"validation","validationCode":"boolean isValidNacosRef(String ref) {\n    return ref != null && ref.split(\"/\").length == 2 && !ref.isBlank() && !ref.startsWith(\"/\") && !ref.endsWith(\"/\");\n}\n// pre-check before invoking the tool\nif (!isValidNacosRef(ref)) throw new IllegalArgumentException(\"Use dataId/group format: \" + ref);","typeGuard":null,"tryCatchPattern":"try {\n    return callback.call(input);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Invalid Nacos config reference format\")) {\n        logger.error(\"Fix placeholder to dataId/group: {}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Validate placeholder strings match ^[^/]+/[^/]+$ before templating.","Always include the group explicitly, even when it is DEFAULT_GROUP.","Avoid dataIds or groups containing '/' characters, or use an escaping scheme."],"tags":["nacos","config","format","placeholder"],"backgroundTag":"invalid-argument-format","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}