dgraph-io/dgraph · error

Unexpected end of input.

Error message

Unexpected end of input.

What it means

LexQuotedString returns 'Unexpected end of input.' when it reaches EOF (rune 0) while scanning a quoted string, meaning the closing quote was never found. Dgraph's lexer requires string literals to be terminated on the same input, so any string that runs to end-of-file without a closing '"' aborts lexing.

Source

Thrown at lex/lexer.go:405

	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 nil
}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add the missing closing double quote to the string literal
  2. Log the full request payload server-side to confirm it is not truncated in transit
  3. Check proxy/gateway body size limits and client serialization
  4. If the literal must span lines or contain quotes, escape them (\") rather than leaving unterminated

Example fix

// before
{
  q(func: eq(name, "Alice))
}
// after
{
  q(func: eq(name, "Alice"))
}
Defensive patterns

Strategy: validation

Validate before calling

// Ensure balanced double quotes before sending
func quotesBalanced(s string) bool {
    inStr, esc := false, false
    for _, r := range s {
        if esc { esc = false; continue }
        if r == '\\' { esc = true; continue }
        if r == '"' { inStr = !inStr }
    }
    return !inStr
}

Try / catch

if err := mutate(payload); err != nil && strings.Contains(err.Error(), "Unexpected end of input") {
    return fmt.Errorf("unterminated string literal in payload: %w", err)
}

Prevention

When it happens

Trigger: A DQL query or RDF N-Quad mutation contains an opening '"' with no matching closing quote before the input ends — e.g. truncated request bodies, heredoc/template rendering that dropped the final quote, or a multi-line literal written without escapes.

Common situations: Large mutations truncated by proxies or size limits; shell heredocs losing the last character; template engines cutting off output; users editing queries and deleting the closing quote.

Understand the failure class

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/245561304db44bd4. Report an issue: GitHub.