{"record":{"id":"12d28a1fe1dc7ebd","repo":"dgraph-io/dgraph","slug":"startuid-length-8-for-key-q-parsed-key-v-12d28a","errorCode":null,"errorMessage":"StartUid length < 8 for key: %q, parsed key: %+v","messagePattern":"StartUid length < 8 for key: %q, parsed key: %\\+v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/keys.go","lineNumber":592,"sourceCode":"\t\t}\n\t\tif !p.HasStartUid {\n\t\t\tbreak\n\t\t}\n\n\t\tif len(k) != 16 {\n\t\t\treturn p, errors.Errorf(\"StartUid length != 8 for key: %q, parsed key: %+v\", key, p)\n\t\t}\n\n\t\tk = k[8:]\n\t\tp.StartUid = binary.BigEndian.Uint64(k)\n\tcase ByteIndex:\n\t\tif !p.HasStartUid {\n\t\t\tp.Term = string(k)\n\t\t\tbreak\n\t\t}\n\n\t\tif len(k) < 8 {\n\t\t\treturn p, errors.Errorf(\"StartUid length < 8 for key: %q, parsed key: %+v\", key, p)\n\t\t}\n\n\t\tterm := k[:len(k)-8]\n\t\tstartUid := k[len(k)-8:]\n\t\tp.Term = string(term)\n\t\tp.StartUid = binary.BigEndian.Uint64(startUid)\n\tcase ByteCount, ByteCountRev:\n\t\tif len(k) < 4 {\n\t\t\treturn p, errors.Errorf(\"count length < 4 for key: %q, parsed key: %+v\", key, p)\n\t\t}\n\t\tp.Count = binary.BigEndian.Uint32(k)\n\n\t\tif !p.HasStartUid {\n\t\t\tbreak\n\t\t}\n\n\t\tif len(k) != 12 {\n\t\t\treturn p, errors.Errorf(\"StartUid length != 8 for key: %q, parsed key: %+v\", key, p)","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/keys.go#L574-L610","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupted index keys on disk, keys truncated by manual slicing, or test fixtures with empty terms where a start-uid key was expected.","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"],"exampleFix":"// before: index key missing start uid bytes\nkey := []byte{byte(x.ByteIndex)} // only 1 byte payload\np, err := x.Parse(key) // StartUid length < 8\n// after\nkey := x.IndexKey(attr, term, startUid) // term + 8-byte startUid","handlingStrategy":"validation","validationCode":"if len(key) < 9 { return fmt.Errorf(\"index key too short: %d\", len(key)) }\nok, err := x.IsDropOpKey(key)","typeGuard":"func isMinIndexKey(key []byte) bool { return len(key) >= 9 }","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","badger","key-parsing","index"],"backgroundTag":"malformed-key-length","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}