dgraph-io/dgraph · error

expected ')', found: %s

Error message

expected ')', found: %s

What it means

Error raised by the RDF parser in chunker/rdf_parser.go when a function call's closing parenthesis is missing or another token appears where ')' is expected. The unexpected token is reported via %s. Fix by correcting the function-call syntax so it is properly closed.

Source

Thrown at chunker/rdf_parser.go:254

	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")
	}
	item := it.Item()
	if item.Typ != itemLeftRound {
		return fmt.Errorf("expected '(' but found %v at facet", item.Val)
	}

	for it.Next() { // parse one key value pair
		// parse key
		item = it.Item()
		if item.Typ != itemText {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add the missing ')' after the variable name.
  2. Remove any extra tokens between '(' and ')' — exactly one variable name is allowed.
  3. Verify the line was not truncated in transit or by an editor.

Example fix

// before
ParseRDF("<s> <p> uid(var .")   // missing ')'
// after
ParseRDF("<s> <p> uid(var) .")
Defensive patterns

Strategy: validation

Validate before calling

matched, _ := regexp.MatchString(`\w+\(\s*[A-Za-z0-9_]+\s*\)`, fnExpr)
if !matched { return errors.New("malformed function call") }

Try / catch

if _, err := parseFunction(it); err != nil {
	if strings.HasPrefix(err.Error(), "expected ')'") {
		return fmt.Errorf("unterminated function call in RDF line: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: ParseRDF input with an unterminated function call, e.g. 'uid(var' missing ')', or extra tokens like 'uid(var var2)' between the parentheses.

Common situations: Truncated lines from file cuts or network transfer; hand-edited queries that dropped the closing paren; multiple arguments typed where only one variable is allowed.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/6b29be142a94e6a0. Report an issue: GitHub.