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 StartUid portion of the key does not have the expected 8-byte length. The raw key and parsed structure are reported via %q and %+v. Indicates a corrupt or malformed key; fix by correcting or regenerating the key data.
Source
Thrown at x/keys.go:580
p.ByteType = k[0]
k = k[1:]
switch p.ByteType {
case ByteData, ByteReverse:
if len(k) < 8 {
return p, errors.Errorf("uid length < 8 for key: %q, parsed key: %+v", key, p)
}
p.Uid = binary.BigEndian.Uint64(k)
if p.Uid == 0 {
return p, errors.Errorf("Invalid UID with value 0 for key: %v", key)
}
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)View on GitHub (pinned to 759e242be6)
Solutions
- Verify the key is exactly 16 bytes for start-uid data keys (hex.Dump the key)
- Regenerate the key using the package's key-construction helpers
- Check for version skew between nodes/writers encoding keys
- If from disk, suspect corruption and restore from backup
Example fix
// before: 12-byte data key with start uid key := buf[:12] p, err := x.Parse(key) // StartUid length != 8 // after key := buf[:16] // 8-byte UID + 8-byte StartUid p, err := x.Parse(key)
Defensive patterns
Strategy: validation
Validate before calling
if len(key) != 17 { return fmt.Errorf("data+startuid key must be 17 bytes, got %d", len(key)) }
ok, err := x.IsDropOpKey(key) Type guard
func isStartUidDataKey(key []byte) bool { return len(key) == 17 } Prevention
- Use x.Key helpers that guarantee 16-byte payload for start-uid keys
- Assert key lengths in unit tests for fixtures
- Pin a single Dgraph version across writers/readers
When it happens
Trigger: Calling Parse/IsDropOpKey with a ByteData or ByteReverse key of length != 16 where HasStartUid is true (the key's type byte indicates start-uid layout).
Common situations: Truncated keys from corrupted storage, manually assembled byte keys of the wrong length, or version-mismatched key encodings between Dgraph components.
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/5aaf84d931b96fe9.
Report an issue: GitHub.