{"record":{"id":"c7cae88c00809efc","repo":"dgraph-io/dgraph","slug":"empty-variable-name-in-function-call","errorCode":null,"errorMessage":"empty variable name in function call","messagePattern":"empty variable name in function call","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/rdf_parser.go","lineNumber":248,"sourceCode":"}\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}\n\titem := it.Item()\n\tif item.Typ != itemLeftRound {\n\t\treturn fmt.Errorf(\"expected '(' but found %v at facet\", item.Val)","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/rdf_parser.go#L230-L266","documentation":"Error raised by the RDF parser in chunker/rdf_parser.go when a function call references a variable with an empty name (e.g. fn with no variable identifier). Indicates malformed input; fix by providing the variable name inside the function call.","triggerScenarios":"ParseRDF input where a function call's parentheses contain only whitespace or a token that trims to the empty string, e.g. 'uid( )' or 'uid(\\t)'.","commonSituations":"Templated queries where the variable placeholder was never filled in; generators emitting empty placeholders; accidental deletion of the variable during editing.","solutions":["Supply a real variable name inside the parentheses.","Fix the template/generator so the variable placeholder is populated before calling ParseRDF.","Strip or skip lines whose function calls have empty variables before parsing."],"exampleFix":"// before\nParseRDF(fmt.Sprintf(\"<s> <p> uid(%s) .\", varName))  // varName == \"\"\n// after\nif varName == \"\" { return errors.New(\"varName required\") }\nParseRDF(fmt.Sprintf(\"<s> <p> uid(%s) .\", varName))","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(varName) == \"\" {\n\treturn errors.New(\"variable name must be non-empty\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := parseFunction(it); err != nil {\n\tif err.Error() == \"empty variable name in function call\" {\n\t\treturn fmt.Errorf(\"populate variable placeholder before parsing: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Check template placeholders are filled before rendering query strings.","Trim and validate variable names at generation time.","Fail fast in generators when a required variable is missing."],"tags":["rdf","parsing","validation","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"}