dgraph-io/dgraph · error
expected variable name, found: %s
Error message
expected variable name, found: %s
What it means
Error raised by the RDF/N-Quads parser in chunker/rdf_parser.go when parsing a variable (e.g. in a _var_ context) and the next token is not a valid variable name. The offending token is included via %s. Indicates malformed input; fix by supplying a valid variable name in the RDF data.
Source
Thrown at chunker/rdf_parser.go:245
}
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
}
func parseFacetsRDF(it *lex.ItemIterator, rnq *api.NQuad) error {
if !it.Next() {
return errors.New("unexpected end of facets")
}View on GitHub (pinned to 759e242be6)
Solutions
- Put a valid variable name inside the parentheses, e.g. uid(var).
- If you meant to pass a value, use the syntax supported for that function instead of a bare literal.
- Check the input line for truncation that removed the variable token.
Example fix
// before
ParseRDF("<s> <p> uid() .")
// after
ParseRDF("<s> <p> uid(var) .") Defensive patterns
Strategy: validation
Validate before calling
func hasVariable(fn string) bool {
open := strings.Index(fn, "(")
close := strings.LastIndex(fn, ")")
return open >= 0 && close > open+1 && strings.TrimSpace(fn[open+1:close]) != ""
} Try / catch
if _, err := parseFunction(it); err != nil {
if strings.HasPrefix(err.Error(), "expected variable name") {
return fmt.Errorf("function call requires exactly one variable: %w", err)
}
return err
} Prevention
- Never emit empty function calls; always pass a variable.
- Use the query-language syntax for literal values instead of functions.
- Validate generated function expressions against a name(variable) regex.
When it happens
Trigger: ParseRDF input with a function call containing something other than a variable between the parentheses, e.g. 'uid()' with nothing inside, or 'uid(0x123)' passing a literal UID instead of a variable.
Common situations: Empty function calls copied from templates; passing raw values where a variable is required; lexer splitting a complex expression into non-variable tokens.
Related errors
- expected '(', 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/23502bf2b6c76a41.
Report an issue: GitHub.