{"record":{"id":"097cbcfff30dc466","repo":"dgraph-io/dgraph","slug":"line-d-column-d","errorCode":null,"errorMessage":"line %d column %d: ","messagePattern":"line (.+?) column (.+?): ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lex/lexer.go","lineNumber":44,"sourceCode":"\tItemEOF ItemType = iota\n\t// ItemError is emitted when there was an error lexing the input.\n\tItemError\n)\n\n// StateFn represents the state of the scanner as a function that returns the next state.\ntype StateFn func(*Lexer) StateFn\n\n// Item represents a unit emitted by the lexer.\ntype Item struct {\n\tTyp    ItemType\n\tVal    string\n\tline   int\n\tcolumn int\n}\n\n// Errorf returns an error message that includes the line and column where the error occurred.\nfunc (i Item) Errorf(format string, args ...interface{}) error {\n\treturn errors.Errorf(\"line %d column %d: \"+format,\n\t\tappend([]interface{}{i.line, i.column}, args...)...)\n}\n\nfunc (i Item) String() string {\n\tif i.Typ == ItemEOF {\n\t\treturn \"EOF\"\n\t}\n\treturn fmt.Sprintf(\"lex.Item [%v] %q at %d:%d\", i.Typ, i.Val, i.line, i.column)\n}\n\n// ItemIterator iterates over the items emitted by a lexer.\ntype ItemIterator struct {\n\tl   *Lexer\n\tidx int\n}\n\n// NewIterator returns a new ItemIterator instance that uses the lexer.\nfunc (l *Lexer) NewIterator() *ItemIterator {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/lex/lexer.go#L26-L62","documentation":"Item.Errorf is a formatting helper on the lexer's Item type in Dgraph's query lexer. It is not an error itself but the mechanism by which every lexer/parser error message gets its 'line %d column %d: ' prefix, pinpointing where in the query input the problem occurred. You see this prefix whenever any lexing or parsing error is reported.","triggerScenarios":"Any call to Item.Errorf or ItemIterator.Errorf with a format string, e.g. when the GraphQL+-/DQL parser reports a syntax error; the prefix is prepended to the underlying message with the item's recorded line and column.","commonSituations":"Developers see 'line 1 column 12: Unexpected ...' when a DQL query sent to Dgraph via HTTP /query or gRPC Query is malformed: unbalanced braces, stray characters, bad arguments in an upsert block, or copy-pasted text with hidden characters.","solutions":["Read the line/column offset in the message and fix the query text at that exact position","Print or log the full query being sent to verify no client-side escaping mangling occurred","Test the failing query in Ratel to get visual error highlighting","If line/column are -1 or nonsense, the iterator was used past EOF; re-validate the query with Lexer.ValidateResult before parsing"],"exampleFix":"// before (mangled multiline query string)\nq := \"upsert { query { q(func: eq(email, \\\"a@b.com\\\")) } mutation { set { uid <email> \\\"c@d.com\\\" . } }\"\n// after (balanced braces, valid DQL)\nq := `upsert { query { q(func: eq(email, \"a@b.com\")) } mutation { set { uid <email> \"c@d.com\" . } } }`","handlingStrategy":"validation","validationCode":"// Before sending, sanity-check the DQL string\nfunc validateQuery(q string) error {\n    l := lex.NewLexer(q)\n    return l.ValidateResult() // surfaces lexer errors with line/column before parse\n}","typeGuard":null,"tryCatchPattern":"err := runQuery(q)\nif err != nil && strings.Contains(err.Error(), \"line \") {\n    // lexer-reported position; extract and show user the offending line\n    return fmt.Errorf(\"query syntax error: %w\", err)\n}","preventionTips":["Test queries in Ratel UI before embedding them in applications","Store DQL in separate template files with linting rather than inline string concatenation","Strip or escape hidden Unicode characters when copying queries from docs/editors","Log the exact query string on parse failure for reproducibility"],"tags":["lexer","query-parsing","dql","error-position"],"backgroundTag":"dql-syntax-error","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}