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

  1. Check the token printed in the error and add the missing '(' right after the function name.
  2. Verify the whole function expression is well-formed: name(variable).
  3. 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

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


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