dgraph-io/dgraph · error
String should start with quote.
Error message
String should start with quote.
What it means
LexQuotedString processes a quoted string literal in the lexer, handling escapes. Before scanning, it backs up and reads one rune; if that rune is not the quote character ('"'), it means the lexer was invoked at a position that does not start a string. The error guards against internal lexer state machines (lexContent, lexFacets, lexFuncOrArg, lexText) dispatching to string lexing incorrectly, usually due to malformed input.
Source
Thrown at lex/lexer.go:400
func (l *Lexer) IsEscChar(r rune) bool {
switch r {
case 'u', 'v', 't', 'b', 'n', 'r', 'f', '"', '\'', '\\':
return true
}
return false
}
// IsEndOfLine returns true if the rune is a Linefeed or a Carriage return.
func IsEndOfLine(r rune) bool {
return r == '\u000A' || r == '\u000D'
}
// LexQuotedString properly processes a quoted string (by taking care of escaped characters).
func (l *Lexer) LexQuotedString() error {
l.Backup()
r := l.Next()
if r != quote {
return errors.Errorf("String should start with quote.")
}
for {
r := l.Next()
if r == EOF {
return errors.Errorf("Unexpected end of input.")
}
if r == '\\' {
r := l.Next()
if !l.IsEscChar(r) {
return errors.Errorf("Not a valid escape char: '%c'", r)
}
continue // eat the next char
}
if r == quote {
break
}
}
return nilView on GitHub (pinned to 759e242be6)
Solutions
- Replace smart/curly quotes with straight ASCII double quotes in the query/mutation
- Check the position reported by the lexer and remove or correctly open the string literal
- Re-encode the input as UTF-8 plain ASCII quotes; some editors autocorrect quotes
- If using the lexer package directly, only call LexQuotedString when the previous rune is a quote
Example fix
// before (curly quote from copy-paste) <0x01> <name> “Alice” . // after <0x01> <name> "Alice" .
Defensive patterns
Strategy: validation
Validate before calling
// Reject quote characters that are not ASCII '"'
func checkQuotes(s string) error {
for i, r := range s {
if (r == '\u201c' || r == '\u201d' || r == '\u2018' || r == '\u2019') {
return fmt.Errorf("non-ASCII quote at byte %d", i)
}
}
return nil
} Try / catch
if err := runQuery(q); err != nil && strings.Contains(err.Error(), "String should start with quote") {
return fmt.Errorf("misplaced quote in query: %w", err)
} Prevention
- Disable smart-quote autocorrect in editors for DQL/RDF files
- Save query files as plain UTF-8 ASCII where possible
- Use builder libraries or JSON mutations to avoid manual quoting
When it happens
Trigger: The lexer's state function hands control to LexQuotedString but the current rune is not a '"' — e.g. input contains a quote-like construct the dispatcher mispredicted, or custom/embedded lexer usage calls LexQuotedString at a non-quote position.
Common situations: Queries or RDF mutations with a lone or misplaced quotation mark, smart quotes (' ' ') pasted from editors or Word, or facet values that start a string incorrectly.
Related errors
- Unexpected end of input.
- Not a valid escape char: '%c'
- Unexpected end of IRI
- Unexpected character %q while parsing IRI
- line %d column %d:
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/ccc9571d98ab7ec0.
Report an issue: GitHub.