{"record":{"id":"42c740e1ec97fbd1","repo":"dgraph-io/dgraph","slug":"invalid-data-type","errorCode":null,"errorMessage":"Invalid data type","messagePattern":"Invalid data type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/keys.go","lineNumber":617,"sourceCode":"\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)\n\t\t}\n\n\t\tk = k[4:]\n\t\tp.StartUid = binary.BigEndian.Uint64(k)\n\tdefault:\n\t\t// Some other data type.\n\t\treturn p, errors.Errorf(\"Invalid data type\")\n\t}\n\treturn p, nil\n}\n\nfunc IsDropOpKey(key []byte) (bool, error) {\n\tpk, err := Parse(key)\n\tif err != nil {\n\t\treturn false, errors.Wrapf(err, \"could not parse key %s\", hex.Dump(key))\n\t}\n\n\tif pk.IsData() && ParseAttr(pk.Attr) == \"dgraph.drop.op\" {\n\t\treturn true, nil\n\t}\n\treturn false, nil\n}\n\n// These predicates appear for queries that have * as predicate in them.\nvar starAllPredicateMap = map[string]struct{}{","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/keys.go#L599-L635","documentation":"Error returned by x/keys.go when a key's byte prefix maps to an unknown or invalid data type during key parsing. Indicates a corrupt key or unsupported key format; fix by writing keys only through the supported key-construction functions.","triggerScenarios":"Calling Parse/IsDropOpKey on a key whose first byte is not a known key-type constant, e.g. schema, mutation or other non-posting keys being fed to Parse.","commonSituations":"Passing non-posting badger keys (schema keys, ACL keys) to Parse, version mismatch introducing new key types, or corrupted type byte.","solutions":["Confirm the key is a posting/data-family key before calling Parse","Filter out non-posting keys (schema, drop-op markers) by prefix/type before parsing","Check for version skew where newer keys are read by older code","Dump the first byte and compare against the known key-type constants"],"exampleFix":"// before: parsing any badger key\npk, err := x.Parse(it.Item().Key())\n// after: skip unknown types first\ntypeID := it.Item().Key()[0]\nif typeID == byte(x.ByteSchema) { continue }\npk, err := x.Parse(it.Item().Key())","handlingStrategy":"type-guard","validationCode":"known := map[byte]bool{byte(x.ByteData): true, byte(x.ByteReverse): true, byte(x.ByteIndex): true, byte(x.ByteCount): true, byte(x.ByteCountRev): true}\nif !known[key[0]] { return nil } // skip non-posting keys\nok, err := x.IsDropOpKey(key)","typeGuard":"func isPostingKey(key []byte) bool {\n  if len(key) == 0 { return false }\n  switch key[0] {\n  case byte(x.ByteData), byte(x.ByteReverse), byte(x.ByteIndex), byte(x.ByteCount), byte(x.ByteCountRev):\n    return true\n  }\n  return false\n}","tryCatchPattern":null,"preventionTips":["Only feed posting-family keys to Parse; route schema/other keys elsewhere","Iterate badger iterators with prefix filters for posting keys","Log unknown type bytes to detect version skew early"],"tags":["go","badger","key-parsing"],"backgroundTag":"unknown-key-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}