{"record":{"id":"cd7d0d2f13290bc1","repo":"alibaba/spring-ai-alibaba","slug":"toolnameexists","errorCode":"ToolNameExists","errorMessage":"Tool name already exists.","messagePattern":"Tool name already exists\\.","errorType":"error_code","errorClass":"BizException","httpStatus":400,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/PluginServiceImpl.java","lineNumber":276,"sourceCode":"\n\t\treturn new PagingList<>(query.getCurrent(), query.getSize(), pageResult.getTotal(), plugins);\n\t}\n\n\t/**\n\t * Creates a new tool for a plugin\n\t * @param tool Tool information\n\t * @return Generated tool ID\n\t */\n\t@Override\n\tpublic String createTool(Tool tool) {\n\t\ttry {\n\t\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\t\tPlugin plugin = getPlugin(tool.getPluginId());\n\n\t\t\t// check if tool name exists\n\t\t\tToolEntity toolEntity = getToolByName(context.getWorkspaceId(), plugin.getPluginId(), tool.getName());\n\t\t\tif (toolEntity != null) {\n\t\t\t\tthrow new BizException(ErrorCode.TOOL_NAME_EXISTS.toError());\n\t\t\t}\n\n\t\t\tTool.ToolConfig config = tool.getConfig();\n\t\t\tList<ApiParameter> inputParams = config.getInputParams();\n\t\t\tif (!CollectionUtils.isEmpty(inputParams)) {\n\t\t\t\tfor (ApiParameter apiParameter : inputParams) {\n\t\t\t\t\tString location = apiParameter.getLocation();\n\t\t\t\t\tif (\"Get\".equals(config.getRequestMethod()) && location.equals(\"Body\")) {\n\t\t\t\t\t\tthrow new BizException(\n\t\t\t\t\t\t\t\tErrorCode.INVALID_PARAMS.toError(\"input_params\", \"Get method not support body params\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// convert to swagger yaml\n\t\t\tString yaml = OpenApiUtils.buildOpenAPIYaml(plugin, tool);\n\n\t\t\tif (StringUtils.isBlank(yaml) || !CollectionUtils.isEmpty(OpenApiUtils.parseOpenAPIObject(yaml))) {","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/PluginServiceImpl.java#L258-L294","documentation":"createTool in PluginServiceImpl throws BizException(TOOL_NAME_DUPLICATED) when getToolByName finds an existing tool with the same name under the same plugin in the workspace — tool names must be unique per plugin.","triggerScenarios":"createTool(tool) where getToolByName(workspaceId, plugin.getPluginId(), tool.getName()) returns non-null.","commonSituations":"Retrying a create that already succeeded; copying a tool into the same plugin without renaming; importing tool definitions with colliding names.","solutions":["Rename the tool to a unique name within the plugin","Look up existing tool names under the plugin before creating","Catch ToolNameExists BizException and surface a conflict message"],"exampleFix":"// before\ntool.setName(\"get_weather\");\npluginService.createTool(tool);\n// after\nString name = \"get_weather\";\nint i = 2;\nwhile (toolExists(pluginId, name)) { name = \"get_weather_\" + i++; }\ntool.setName(name);\npluginService.createTool(tool);","handlingStrategy":"validation","validationCode":"// unique-name suggestion helper\nString base = tool.getName(); String name = base; int i = 2;\nwhile (toolNameExists(pluginId, name)) { name = base + \"_\" + i++; }\ntool.setName(name);","typeGuard":null,"tryCatchPattern":"try {\n    pluginService.createTool(tool);\n} catch (BizException e) {\n    throw new ResponseStatusException(HttpStatus.CONFLICT, \"Tool name already exists\");\n}","preventionTips":["List existing tool names under the plugin before create","Make create-tool requests idempotent on retry","Enforce unique names in the UI form validation","Avoid importing tools without deduplicating names"],"tags":["tool","duplicate","conflict","plugin"],"backgroundTag":"file-already-exists","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"}