{"record":{"id":"437fab3c922af87c","repo":"xai-org/x-algorithm","slug":"failed-to-parse-type-signature-s-s","errorCode":null,"errorMessage":"Failed to parse Type signature '%s'%s","messagePattern":"Failed to parse Type signature '(.+?)'(.+?)","errorType":"validation","errorClass":"ParseFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/Parser.java","lineNumber":221,"sourceCode":"    try {\n      root = (Tree) parser.type().getTree();\n    } catch (Exception e) {\n      if (e.getCause() instanceof RecognitionException) {\n        RecognitionException re = (RecognitionException) e.getCause();\n        String extraMsg = \"\";\n        if (re.token != null) {\n          String unexpectedTok = \"<EOF>\";\n          if (re.getUnexpectedType() >= 0) {\n            unexpectedTok = BotMakerParser.tokenNames[re.getUnexpectedType()];\n          }\n          extraMsg = String.format(\n              \": line %d col %d, near token <%s>: unexpected token %s\",\n              re.token.getLine(), re.token.getCharPositionInLine() + 1,\n              re.token.getText(), unexpectedTok);\n        } else if (re.line != 0) {\n          extraMsg = String.format(\": line %d col %d\", re.line, re.charPositionInLine + 1);\n        }\n        throw new ParseFailure(\n            String.format(\"Failed to parse Type signature '%s'%s\", expr, extraMsg),\n            re);\n      }\n      throw new ParseFailure(\"unknown parse failure\", e);\n    }\n\n    return root;\n  }\n\n\n  public static String printTree(Tree tree) {\n    if (tree.getChildCount() == 0) {\n      return String.format(\"leaf: %s, type; %d\", tree.getText(), tree.getType());\n    }\n    String s = String.format(\n        \"\\nnode: %s, type: %s, numChildren:%d\\n\",\n        tree.getText(), tree.getType(), tree.getChildCount());\n    for (int i = 0; i < tree.getChildCount(); i++) {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/Parser.java#L203-L239","documentation":"Thrown by Parser.parseType when the input expression cannot be parsed as a Type signature in the BotMaker grammar. It mirrors the other parse errors: it formats the expression plus RecognitionException-derived position/token context into a ParseFailure.","triggerScenarios":"Calling parseType (or tree) with an invalid type expression: unknown type constructor, malformed generics/nesting, missing closing bracket, or stray characters.","commonSituations":"Type strings built programmatically (string concatenation of type names) that produce invalid nesting; typos in hand-written type annotations; grammar changes between versions rejecting previously accepted syntax.","solutions":["Fix the type expression at the reported line/col","Compare against known-good type strings in tests to confirm the expected shape","If generating type strings dynamically, add a builder/format helper instead of raw concatenation","Catch ParseFailure and include the offending expr in user-facing diagnostics"],"exampleFix":"// before\nTree t = Parser.parseType(\"map<string,\");\n\n// after\nTree t = Parser.parseType(\"map<string,int>\");","handlingStrategy":"try-catch","validationCode":"// Cheap pre-check for balanced angle brackets/parens in type expressions\nboolean balancedType(String t) {\n  int a = 0, b = 0;\n  for (char c : t.toCharArray()) {\n    if (c == '<') a++; if (c == '>') a--;\n    if (c == '(') b++; if (c == ')') b--;\n  }\n  return a == 0 && b == 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  Tree t = Parser.parseType(expr);\n} catch (ParseFailure pf) {\n  throw new IllegalArgumentException(\"Bad type expression: \" + expr, pf);\n}","preventionTips":["Use helper builders for composed type strings","Test type-expression generation in unit tests","Log the expr with the failure"],"tags":["parsing","type-signature","antlr","botmaker"],"backgroundTag":"parse-error-invalid-syntax","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}