{"record":{"id":"a47e9336be1add46","repo":"dgraph-io/dgraph","slug":"item-val","errorCode":null,"errorMessage":"item.Val","messagePattern":"item\\.Val","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lex/lexer.go","lineNumber":189,"sourceCode":"func (l *Lexer) Reset(input string) {\n\t// Pick the slices so we can reuse it.\n\titem := l.items\n\twidthStack := l.widthStack\n\n\t*l = Lexer{}\n\tl.Input = input\n\tl.items = item[:0]\n\tl.widthStack = widthStack[:0]\n\tl.Line = 1\n}\n\n// ValidateResult verifies whether the entire input can be lexed without errors.\nfunc (l *Lexer) ValidateResult() error {\n\tit := l.NewIterator()\n\tfor it.Next() {\n\t\titem := it.Item()\n\t\tif item.Typ == ItemError {\n\t\t\treturn errors.New(item.Val)\n\t\t}\n\t}\n\treturn nil\n}\n\n// Run  executes the given StateFn on the lexer and returns the lexer.\nfunc (l *Lexer) Run(f StateFn) *Lexer {\n\tfor state := f; state != nil; {\n\t\t// The following statement is useful for debugging.\n\t\t// fmt.Printf(\"Func: %v\\n\", runtime.FuncForPC(reflect.ValueOf(state).Pointer()).Name())\n\t\tstate = state(l)\n\t}\n\treturn l\n}\n\n// Errorf returns the error state function.\nfunc (l *Lexer) Errorf(format string, args ...interface{}) StateFn {\n\tl.items = append(l.items, Item{","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/lex/lexer.go#L171-L207","documentation":"Lexer.ValidateResult walks every lexed item and returns errors.New(item.Val) when it encounters an ItemError token. The message is the raw lexer error text stored in the item, so any lexing failure (illegal character, unterminated string, bad escape) surfaces here verbatim. It is used by all query/mutation entry points (ParseRDF, ParseDQL, ParseWithNeedVars, ParseMutation) to fail fast before parsing.","triggerScenarios":"Calling ValidateResult (directly or via ParseDQL/ParseRDF/ParseMutation) on input containing a character or construct the lexer cannot tokenize, e.g. an unterminated quoted string, invalid escape, or stray symbol; the error message is whatever text was recorded in the ItemError item.","commonSituations":"Sending RDF N-Quads mutations with a bad literal, or DQL queries with unescaped quotes/braces; also seen when RDFN-Quad lines use characters outside what the lexer accepts.","solutions":["Read item.Val in the error — it states the exact lexical problem — and fix that character/construct in the input","Always call ValidateResult (or the Parse entry point) and check the error before continuing with parsed output","Escape quotes and backslashes inside string literals properly","If parsing RDF, verify each N-Quad line terminates with ' .' and literals are quoted"],"exampleFix":"// before\nerr := l.ValidateResult() // \"unterminated quoted string\"\n// after: fix input then guard\nif err := l.ValidateResult(); err != nil {\n    return fmt.Errorf(\"invalid query: %v\", err)\n}","handlingStrategy":"validation","validationCode":"l := lex.NewLexer(input)\nif err := l.ValidateResult(); err != nil {\n    return fmt.Errorf(\"lexical error in input: %v\", err)\n}\n// proceed to parse only if valid","typeGuard":null,"tryCatchPattern":"if err := l.ValidateResult(); err != nil {\n    return fmt.Errorf(\"invalid input: %v\", err) // error text is the lexer's item.Val\n}","preventionTips":["Always run ValidateResult before parsing to get the earliest failure point","Escape quotes and backslashes in string literals","Ensure RDF lines end with ' .' and literals are properly quoted","Validate user-supplied input before embedding it in mutations"],"tags":["lexer","validation","dql","rdf"],"backgroundTag":"dql-syntax-error","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}