MyCATApache/Mycat-Server · error · SQLNonTransientException

Function is not in right format!

Error message

Function is not in right format!

What it means

FunctionParser.parseFunction scans a function-definition string (rule function config) character by character expecting a specific structure of name/arguments (state machine with flags); if the loop ends without reaching the valid terminal state, it throws 'Function is not in right format!'. The configured function expression does not conform to the expected grammar.

Solutions

  1. Fix the function string in the config to the documented format: name(arg1,arg2,...) with balanced parentheses and comma-separated arguments
  2. Compare against a working example of the same function type in the docs/tests
  3. Validate the config file with a syntax checker before loading; check for invisible characters/whitespace from copy-paste

Example fix

// before (rule.xml)
<property name="function">partition-hash-int(id 4</property>
// after
<property name="function">partition-hash-int(id,4)</property>
Defensive patterns

Strategy: validation

Validate before calling

if (!functionExpr.matches("[A-Za-z0-9_]+\\s*\\([^()]*\\)")) {
    throw new IllegalArgumentException("function config not in name(arg1,arg2,...) format: " + functionExpr);
}

Try / catch

try { Function f = new FunctionParser().parseFunction(expr); } catch (SQLNonTransientException e) { if ("Function is not in right format!".equals(e.getMessage())) { /* fix rule.xml function string */ } }

Prevention

When it happens

Trigger: parseFunction is given a malformed function definition string — missing parentheses, unterminated argument list, stray characters, or arguments separated incorrectly — so the parse state machine finishes without returning a Function.

Common situations: Typo or wrong syntax in rule.xml / partition function expressions; copy-pasted config with missing commas or brackets; editing function arguments and leaving an unbalanced ')'.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/e2ea20d7adced7b2. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/parser/primitive/FunctionParser.java:103

                    buffer.append(current);
                    break;
                case Commons.QUOTE:
                    if (flag == 0) {
                        flag = 1;
                    } else if (flag == 1) {
                        flag = 3;
                    }
                case Commons.DOUBLE_QUOTE:
                    if (flag == 0) {
                        flag = 2;
                    } else if (flag == 2) {
                        flag = 3;
                    }
                default:
                    buffer.append(current);
            }
        }
        throw new SQLNonTransientException("Function is not in right format!");
    }

    public static List<String> getFields(Function function){
        List<String> fields = new LinkedList<>();
        for(Identifier identifier : function.getArguments()){
            if(identifier instanceof Field){
                fields.add(identifier.getName());
            } else if (identifier instanceof Function){
                fields.addAll(getFields((Function) identifier));
            }
        }
        return fields;
    }
    public static void main(String[] args) throws SQLNonTransientException {
        Function function = FunctionParser.parseFunction("function1(arg1,a.t,\"ast()\",function2(c.t,function3(x)))");
        System.out.println(getFields(function));
    }
}

View on GitHub (pinned to 65f8d8beb7)