dgraph-io/dgraph · error
expected '(', found: %s
Error message
expected '(', found: %s What it means
parseFunction parses a function token produced by the RDF lexer and expects an opening parenthesis immediately after the function name. If the next lexer item is not '(', parsing aborts with this message showing the offending token.
Source
Thrown at chunker/rdf_parser.go:240
}
if !sane(rnq.Subject) || !sane(rnq.Predicate) || !sane(rnq.ObjectId) {
// Don't format the full line, as it may contain sensitive information
return rnq, fmt.Errorf("NQuad failed sanity check. Subject: %q, Predicate: %q, ObjectId: %q",
rnq.Subject, rnq.Predicate, rnq.ObjectId)
}
return rnq, nil
}
// parseFunction parses uid(<var name>) and returns
// uid(<var name>) after striping whitespace if any
func parseFunction(it *lex.ItemIterator) (string, error) {
item := it.Item()
s := item.Val
it.Next()
if item = it.Item(); item.Typ != itemLeftRound {
return "", fmt.Errorf("expected '(', found: %s", item.Val)
}
it.Next()
if item = it.Item(); item.Typ != itemVarName {
return "", fmt.Errorf("expected variable name, found: %s", item.Val)
}
if strings.TrimSpace(item.Val) == "" {
return "", errors.New("empty variable name in function call")
}
s += "(" + item.Val + ")"
it.Next()
if item = it.Item(); item.Typ != itemRightRound {
return "", fmt.Errorf("expected ')', found: %s", item.Val)
}
return s, nil
}View on GitHub (pinned to 759e242be6)
Solutions
- Check the token printed in the error and add the missing '(' right after the function name.
- Verify the whole function expression is well-formed: name(variable).
- Re-escape or re-quote the line if shell or templating stripped characters before reaching ParseRDF.
Example fix
// before
ParseRDF("<s> <p> uid var .") // 'uid var' missing '('
// after
ParseRDF("<s> <p> uid(var) .") Defensive patterns
Strategy: validation
Validate before calling
func validFunctionCall(s string) bool {
i := strings.Index(s, "(")
return i > 0 && strings.HasSuffix(s, ")")
} Try / catch
if _, err := parseFunction(it); err != nil {
if strings.HasPrefix(err.Error(), "expected '('") {
return fmt.Errorf("malformed function in RDF line: %w", err)
}
return err
} Prevention
- Write function calls as name(variable) with both parentheses.
- Avoid hand-editing RDF lines containing function expressions.
- Escape input through shells/templates carefully so parens survive.
- Test generated lines with ParseRDF in CI before bulk import.
When it happens
Trigger: Calling ParseRDF on a line containing a malformed function expression, e.g. a function name token not followed by '(' — such as 'uid 0x1' or truncated input where the '(' was dropped.
Common situations: Hand-edited RDF/mutation lines where a function call like uid(...) lost its parenthesis; copy-paste errors from docs; lexer treating unexpected characters as a separate token.
Related errors
- expected variable name, found: %s
- expected ')', found: %s
- NQuad failed sanity check. Subject: %q, Predicate: %q, Objec
- empty variable name in function call
- unexpected end of facets
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/bca8742b038f2242.
Report an issue: GitHub.