{"record":{"id":"a41fa16a236cbb9e","repo":"NationalSecurityAgency/ghidra","slug":"function-tag-already-exists-a41fa1","errorCode":null,"errorMessage":"Function tag already exists","messagePattern":"Function tag already exists","errorType":"validation","errorClass":"LSHException","httpStatus":null,"severity":"warning","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java","lineNumber":2963,"sourceCode":"\t\tresponse.info = info;\n\t}\n\n\t/**\n\t * Entry point for the Elasticsearch version of InstallTagRequest command:\n\t *   Install a new function tag to be managed by this data\n\t * @param query is command parameters\n\t * @throws LSHException if the command is misconfigured\n\t * @throws ElasticException for communication problems with the server\n\t */\n\tprivate void fdbInstallTag(InstallTagRequest query) throws LSHException, ElasticException {\n\t\tfinal ResponseInfo response = query.installresponse;\n\t\tif (!CategoryRecord.enforceTypeCharacters(query.tag_name)) {\n\t\t\tthrow new LSHException(\"Bad characters in proposed function tag\");\n\t\t}\n\t\t// Check for existing tag\n\t\tif (info.functionTags != null) {\n\t\t\tif (info.functionTags.contains(query.tag_name)) {\n\t\t\t\tthrow new LSHException(\"Function tag already exists\");\n\t\t\t}\n\t\t}\n\t\tif (info.functionTags == null) {\n\t\t\tinfo.functionTags = new ArrayList<>();\n\t\t}\n\t\t// There are only 32-bits of space in the function record reserved for storing the presence of tags\n\t\tif (info.functionTags.size() >= FunctionTagBSimFilterType.MAX_TAG_COUNT) {\n\t\t\tthrow new LSHException(\n\t\t\t\t\"Cannot allocate new function tag: \" + query.tag_name + \" - Column space is full\");\n\t\t}\n\t\tinfo.functionTags.add(query.tag_name);\n\t\twriteFunctionTags();\n\t\tresponse.info = info;\n\t}\n\n\t/**\n\t * Entry point for the Elasticsearch version of InstallMetadataRequest command:\n\t *   Change some of the global meta-data labels for the database.","sourceCodeStart":2945,"sourceCodeEnd":2981,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java#L2945-L2981","documentation":"fdbInstallTag checks info.functionTags.contains(query.tag_name); if present it throws LSHException(\"Function tag already exists\").","triggerScenarios":"Calling InstallTag for a function tag name that already exists in the database.","commonSituations":"Re-running a tag setup script; an idempotent installer that does not check first.","solutions":["Check existing function tags before installing (or treat 'already exists' as success).","Use a unique tag name."],"exampleFix":"// before\ninstallTag(db, name); // throws on re-run\n// after\nif (!db.getInfo().functionTags.contains(name)) installTag(db, name);","handlingStrategy":"validation","validationCode":"List<String> tags = db.getInfo().functionTags != null ? db.getInfo().functionTags : List.of();\nif (tags.contains(name)) return; // idempotent skip","typeGuard":"boolean alreadyInstalled = db.getInfo().functionTags != null && db.getInfo().functionTags.contains(name);","tryCatchPattern":"try { db.installTag(req); }\ncatch (LSHException e) {\n    if (e.getMessage().equals(\"Function tag already exists\")) return;\n    throw e;\n}","preventionTips":["Make tag-install scripts idempotent by checking info.functionTags first."],"tags":["bsim","tag","duplicate","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}