{"record":{"id":"23502bf2b6c76a41","repo":"dgraph-io/dgraph","slug":"expected-variable-name-found-s","errorCode":null,"errorMessage":"expected variable name, found: %s","messagePattern":"expected variable name, found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/rdf_parser.go","lineNumber":245,"sourceCode":"\t}\n\n\treturn rnq, nil\n}\n\n// parseFunction parses uid(<var name>) and returns\n// uid(<var name>) after striping whitespace if any\nfunc parseFunction(it *lex.ItemIterator) (string, error) {\n\titem := it.Item()\n\ts := item.Val\n\n\tit.Next()\n\tif item = it.Item(); item.Typ != itemLeftRound {\n\t\treturn \"\", fmt.Errorf(\"expected '(', found: %s\", item.Val)\n\t}\n\n\tit.Next()\n\tif item = it.Item(); item.Typ != itemVarName {\n\t\treturn \"\", fmt.Errorf(\"expected variable name, found: %s\", item.Val)\n\t}\n\tif strings.TrimSpace(item.Val) == \"\" {\n\t\treturn \"\", errors.New(\"empty variable name in function call\")\n\t}\n\ts += \"(\" + item.Val + \")\"\n\n\tit.Next()\n\tif item = it.Item(); item.Typ != itemRightRound {\n\t\treturn \"\", fmt.Errorf(\"expected ')', found: %s\", item.Val)\n\t}\n\n\treturn s, nil\n}\n\nfunc parseFacetsRDF(it *lex.ItemIterator, rnq *api.NQuad) error {\n\tif !it.Next() {\n\t\treturn errors.New(\"unexpected end of facets\")\n\t}","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/rdf_parser.go#L227-L263","documentation":"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.","triggerScenarios":"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.","commonSituations":"Empty function calls copied from templates; passing raw values where a variable is required; lexer splitting a complex expression into non-variable tokens.","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."],"exampleFix":"// before\nParseRDF(\"<s> <p> uid() .\")\n// after\nParseRDF(\"<s> <p> uid(var) .\")","handlingStrategy":"validation","validationCode":"func hasVariable(fn string) bool {\n\topen := strings.Index(fn, \"(\")\n\tclose := strings.LastIndex(fn, \")\")\n\treturn open >= 0 && close > open+1 && strings.TrimSpace(fn[open+1:close]) != \"\"\n}","typeGuard":null,"tryCatchPattern":"if _, err := parseFunction(it); err != nil {\n\tif strings.HasPrefix(err.Error(), \"expected variable name\") {\n\t\treturn fmt.Errorf(\"function call requires exactly one variable: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["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."],"tags":["rdf","parsing","syntax","dgraph"],"backgroundTag":"parser-syntax-error","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}