{"record":{"id":"0d1e7fab181f4a35","repo":"NationalSecurityAgency/ghidra","slug":"unknown-query-tag-mainname","errorCode":null,"errorMessage":"Unknown query tag: {mainName}","messagePattern":"Unknown query tag: (.+?)","errorType":"exception","errorClass":"LSHException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/BSimQuery.java","lineNumber":154,"sourceCode":"\t\t\tquery = new InstallCategoryRequest();\n\t\t}\n\t\telse if (mainName.equals(\"installmetadata\")) {\n\t\t\tquery = new InstallMetadataRequest();\n\t\t}\n\t\telse if (mainName.equals(\"installtag\")) {\n\t\t\tquery = new InstallTagRequest();\n\t\t}\n\t\telse if (mainName.equals(\"adjustindex\")) {\n\t\t\tquery = new AdjustVectorIndex();\n\t\t}\n\t\telse if (mainName.equals(\"passwordchange\")) {\n\t\t\tquery = new PasswordChange();\n\t\t}\n\t\telse if (mainName.equals(\"prewarmrequest\")) {\n\t\t\tquery = new PrewarmRequest();\n\t\t}\n\t\telse {\n\t\t\tthrow new LSHException(\"Unknown query tag: \"+mainName);\n\t\t}\n\t\tquery.restoreXml(parser,vectorFactory);\n\t\treturn query;\n\t}\n}\n","sourceCodeStart":136,"sourceCodeEnd":160,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/protocol/BSimQuery.java#L136-L160","documentation":"Thrown by BSimQuery.restoreXml (the static factory method) when the root XML element name does not match any known BSim query type. The method recognizes 16 query tags (querynearest, querynearestvector, insert, queryinfo, update, queryname, delete, createdatabase, querychildren, querycluster, querypair, installcategory, installmetadata, installtag, adjustindex, passwordchange, prewarmrequest). Any other root tag triggers this exception.","triggerScenarios":"Parsing an XML document whose root element is not one of the recognized BSim query tags. This happens when feeding a non-BSim XML file, a BSim protocol message from a newer/older version that uses an unrecognized tag, or a malformed hand-crafted XML. The method peeks the root element name and tries to match it against the known set.","commonSituations":"Version mismatch: the XML was generated by a newer Ghidra/BSim version that introduced a new query type not recognized by the running version; a user or tool constructed an XML file with a typo in the root tag; the XML file is not a BSim query at all (wrong file passed); the parser was pointed at the wrong file.","solutions":["Verify the XML root element matches one of the 16 recognized query tags (querynearest, insert, queryinfo, etc.).","Ensure the Ghidra/BSim version that generated the XML matches or is compatible with the version parsing it.","Print the root element name (parser.peek().getName()) before restoreXml to debug.","If you have a custom query type, extend BSimQuery and register it in the factory."],"exampleFix":"// before\nelse {\n    throw new LSHException(\"Unknown query tag: \"+mainName);\n}\n\n// after — list valid tags in the error\nelse {\n    throw new LSHException(\"Unknown query tag: '\" + mainName + \"'. \" +\n        \"Valid tags: querynearest, querynearestvector, insert, queryinfo, \" +\n        \"update, queryname, delete, createdatabase, querychildren, querycluster, \" +\n        \"querypair, installcategory, installmetadata, installtag, adjustindex, \" +\n        \"passwordchange, prewarmrequest\");\n}","handlingStrategy":"validation","validationCode":"// Validate the XML root element before calling restoreXml\nSet<String> validTags = Set.of(\"querynearest\", \"querynearestvector\", \"insert\",\n    \"queryinfo\", \"update\", \"queryname\", \"delete\", \"createdatabase\",\n    \"querychildren\", \"querycluster\", \"querypair\", \"installcategory\",\n    \"installmetadata\", \"installtag\", \"adjustindex\", \"passwordchange\",\n    \"prewarmrequest\");\nString rootName = parser.peek().getName();\nif (!validTags.contains(rootName)) {\n    throw new IllegalArgumentException(\n        \"Root element '\" + rootName + \"' is not a recognized BSim query tag. \" +\n        \"Valid tags: \" + validTags);\n}","typeGuard":"public static final Set<String> VALID_BSIM_QUERY_TAGS = Set.of(\n    \"querynearest\", \"querynearestvector\", \"insert\", \"queryinfo\", \"update\",\n    \"queryname\", \"delete\", \"createdatabase\", \"querychildren\", \"querycluster\",\n    \"querypair\", \"installcategory\", \"installmetadata\", \"installtag\",\n    \"adjustindex\", \"passwordchange\", \"prewarmrequest\");\n\npublic static boolean isValidQueryRootTag(String tagName) {\n    return VALID_BSIM_QUERY_TAGS.contains(tagName);\n}","tryCatchPattern":"try {\n    BSimQuery<?> query = BSimQuery.restoreXml(parser, vectorFactory);\n} catch (LSHException e) {\n    if (e.getMessage().startsWith(\"Unknown query tag\")) {\n        // Version mismatch or wrong file — check the tag name\n        String tag = parser.peek().getName();\n        throw new IllegalArgumentException(\n            \"Unrecognized BSim query tag '\" + tag + \"'. \" +\n            \"Ensure sender and receiver use compatible Ghidra versions.\", e);\n    }\n    throw e;\n}","preventionTips":["Ensure the Ghidra/BSim version parsing the XML matches or is compatible with the version that generated it.","Validate the XML root element name against the known tag set before calling restoreXml.","Log the root tag name when parsing fails for quick diagnosis.","Do not pass arbitrary XML files to BSimQuery.restoreXml — verify the source first."],"tags":["bsim","xml-parsing","protocol","version-mismatch"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}