dgraph-io/dgraph · error
Unable to peek: %v
Error message
Unable to peek: %v
What it means
parseNamespace in the schema lexer/parser peeks 2 tokens ahead to read a namespace like [0x1] at the start of a schema block. If the token iterator cannot peek that far (EOF or iterator exhausted), the parser wraps the underlying peek error with 'Unable to peek: %v'. It means the schema text ended before a namespace declaration could be read.
Source
Thrown at schema/parse.go:584
if it.Item().Typ == itemExclamationMark {
it.Next()
}
}
if it.Item().Typ != itemNewLine {
return nil, it.Item().Errorf("Expected new line after field declaration. Got %v",
it.Item().Val)
}
glog.Warningf("Type declaration for type %s includes deprecated information about field type "+
"for field %s which will be ignored.", typeName, x.ParseAttr(field.Predicate))
return field, nil
}
func parseNamespace(it *lex.ItemIterator) (uint64, error) {
nextItems, err := it.Peek(2)
if err != nil {
return 0, errors.Errorf("Unable to peek: %v", err)
}
if nextItems[0].Typ != itemNumber || nextItems[1].Typ != itemRightSquare {
return 0, errors.Errorf("Typed oes not match the expected")
}
ns, err := strconv.ParseUint(nextItems[0].Val, 0, 64)
if err != nil {
return 0, err
}
it.Next()
it.Next()
// We have parsed the namespace. Now move to the next item.
if !it.Next() {
return 0, errors.Errorf("No schema found after namespace. Got: %v", nextItems[0])
}
return ns, nil
}
// ParsedSchema represents the parsed schema and type updates.View on GitHub (pinned to 759e242be6)
Solutions
- Provide the complete schema text, including '<predicate>: <type> .' entries after the [namespace] section
- Check the schema source file for truncation (verify it ends with a newline/type declarations)
- If namespaces are not needed, omit the '[' bracket entirely instead of emitting a dangling one
- Log the raw schema string before Parse to confirm what is actually being parsed
Example fix
// before schema := "name: string @index(exact) .\n[0x1]" // truncated after namespace // after schema := "name: string @index(exact) .\n[0x1]\nname: string @index(exact) ."
Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(schemaStr) == "" || strings.HasSuffix(strings.TrimSpace(schemaStr), "[") {
return fmt.Errorf("schema text truncated before namespace")
}
err := schema.Parse(schemaStr, 0, 1) Try / catch
if _, err := schema.Parse(s, 0, 1); err != nil {
if strings.Contains(err.Error(), "Unable to peek") {
log.Fatalf("truncated schema: %v\nraw=%q", err, s)
}
return err
} Prevention
- Always emit complete '<pred>: <type> .' lines after any [ns] header
- Checksum/verify schema files before upload
- Log the raw schema string on parse failure
- Never hand-edit production schema strings without re-validating
When it happens
Trigger: Calling schema.Parse / ParseWithNamespace on schema DQL whose text terminates right after '[' or truncates before '<predicate>: type' following the [ns] token, e.g. an empty or cut-off schema string.
Common situations: Schema file truncated during upload/copy; passing an empty string; manually editing schema and deleting the body after the namespace bracket; tooling generating schema programmatically that stops emitting after the opening bracket.
Related errors
- Typed oes not match the expected
- No schema found after namespace. Got: %v
- While parsing namespace:
- NQuad failed sanity check. Subject: %q, Predicate: %q, Objec
- expected '(', found: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/d27034e016e6abd8.
Report an issue: GitHub.