dgraph-io/dgraph · error
StartUid length < 8 for key: %q, parsed key: %+v
Error message
StartUid length < 8 for key: %q, parsed key: %+v
What it means
Error returned by x/keys.go while parsing a key when the remaining bytes contain fewer than 8 bytes for the StartUid field. The raw key and parsed structure are reported via %q and %+v. Indicates a truncated or malformed key; fix by correcting or regenerating the key data.
Source
Thrown at x/keys.go:592
}
if !p.HasStartUid {
break
}
if len(k) != 16 {
return p, errors.Errorf("StartUid length != 8 for key: %q, parsed key: %+v", key, p)
}
k = k[8:]
p.StartUid = binary.BigEndian.Uint64(k)
case ByteIndex:
if !p.HasStartUid {
p.Term = string(k)
break
}
if len(k) < 8 {
return p, errors.Errorf("StartUid length < 8 for key: %q, parsed key: %+v", key, p)
}
term := k[:len(k)-8]
startUid := k[len(k)-8:]
p.Term = string(term)
p.StartUid = binary.BigEndian.Uint64(startUid)
case ByteCount, ByteCountRev:
if len(k) < 4 {
return p, errors.Errorf("count length < 4 for key: %q, parsed key: %+v", key, p)
}
p.Count = binary.BigEndian.Uint32(k)
if !p.HasStartUid {
break
}
if len(k) != 12 {
return p, errors.Errorf("StartUid length != 8 for key: %q, parsed key: %+v", key, p)View on GitHub (pinned to 759e242be6)
Solutions
- Inspect the key bytes and ensure there are at least 8 trailing bytes for the StartUid
- Regenerate the index key via the library's index-key helpers
- Check the writer that produced the key for truncation bugs
- If persistent in storage, treat as corruption and restore
Example fix
// before: index key missing start uid bytes
key := []byte{byte(x.ByteIndex)} // only 1 byte payload
p, err := x.Parse(key) // StartUid length < 8
// after
key := x.IndexKey(attr, term, startUid) // term + 8-byte startUid Defensive patterns
Strategy: validation
Validate before calling
if len(key) < 9 { return fmt.Errorf("index key too short: %d", len(key)) }
ok, err := x.IsDropOpKey(key) Type guard
func isMinIndexKey(key []byte) bool { return len(key) >= 9 } Prevention
- Never truncate key bytes when slicing buffers
- Validate restored backups with badger tooling before use
- Generate index keys through x.IndexKey instead of manual concatenation
When it happens
Trigger: Calling Parse/IsDropOpKey with a ByteIndex key where HasStartUid is true but len(k) < 8, i.e. the term portion is empty or the StartUid bytes are missing.
Common situations: Corrupted index keys on disk, keys truncated by manual slicing, or test fixtures with empty terms where a start-uid key was expected.
Related errors
- Invalid UID with value 0 for key: %v
- StartUid length != 8 for key: %q, parsed key: %+v
- count length < 4 for key: %q, parsed key: %+v
- Invalid data type
- could not parse key %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/12d28a1fe1dc7ebd.
Report an issue: GitHub.