xai-org/x-algorithm · error · ParseFailure

Failed to parse Type signature '%s'%s

Error message

Failed to parse Type signature '%s'%s

What it means

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.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Parser.java:221

    try {
      root = (Tree) parser.type().getTree();
    } catch (Exception e) {
      if (e.getCause() instanceof RecognitionException) {
        RecognitionException re = (RecognitionException) e.getCause();
        String extraMsg = "";
        if (re.token != null) {
          String unexpectedTok = "<EOF>";
          if (re.getUnexpectedType() >= 0) {
            unexpectedTok = BotMakerParser.tokenNames[re.getUnexpectedType()];
          }
          extraMsg = String.format(
              ": line %d col %d, near token <%s>: unexpected token %s",
              re.token.getLine(), re.token.getCharPositionInLine() + 1,
              re.token.getText(), unexpectedTok);
        } else if (re.line != 0) {
          extraMsg = String.format(": line %d col %d", re.line, re.charPositionInLine + 1);
        }
        throw new ParseFailure(
            String.format("Failed to parse Type signature '%s'%s", expr, extraMsg),
            re);
      }
      throw new ParseFailure("unknown parse failure", e);
    }

    return root;
  }


  public static String printTree(Tree tree) {
    if (tree.getChildCount() == 0) {
      return String.format("leaf: %s, type; %d", tree.getText(), tree.getType());
    }
    String s = String.format(
        "\nnode: %s, type: %s, numChildren:%d\n",
        tree.getText(), tree.getType(), tree.getChildCount());
    for (int i = 0; i < tree.getChildCount(); i++) {

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Fix the type expression at the reported line/col
  2. Compare against known-good type strings in tests to confirm the expected shape
  3. If generating type strings dynamically, add a builder/format helper instead of raw concatenation
  4. Catch ParseFailure and include the offending expr in user-facing diagnostics

Example fix

// before
Tree t = Parser.parseType("map<string,");

// after
Tree t = Parser.parseType("map<string,int>");
Defensive patterns

Strategy: try-catch

Validate before calling

// Cheap pre-check for balanced angle brackets/parens in type expressions
boolean balancedType(String t) {
  int a = 0, b = 0;
  for (char c : t.toCharArray()) {
    if (c == '<') a++; if (c == '>') a--;
    if (c == '(') b++; if (c == ')') b--;
  }
  return a == 0 && b == 0;
}

Try / catch

try {
  Tree t = Parser.parseType(expr);
} catch (ParseFailure pf) {
  throw new IllegalArgumentException("Bad type expression: " + expr, pf);
}

Prevention

When it happens

Trigger: Calling parseType (or tree) with an invalid type expression: unknown type constructor, malformed generics/nesting, missing closing bracket, or stray characters.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/437fab3c922af87c. Report an issue: GitHub.