{"record":{"id":"839349d4c5a26078","repo":"dgraph-io/dgraph","slug":"could-not-parse-key-s-839349","errorCode":null,"errorMessage":"could not parse key %s","messagePattern":"could not parse key (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/keys.go","lineNumber":625,"sourceCode":"\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{}{\n\t\"dgraph.type\": {},\n}\n\nvar aclPredicateMap = map[string]struct{}{\n\t\"dgraph.xid\":             {},\n\t\"dgraph.password\":        {},\n\t\"dgraph.user.group\":      {},\n\t\"dgraph.rule.predicate\":  {},","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/keys.go#L607-L643","documentation":"Generic error returned by x/keys.go when a stored key cannot be parsed according to its expected encoding. The offending key is reported via %s. Indicates corruption or an incompatible key format; fix by identifying how the key was written and regenerating it correctly.","triggerScenarios":"checkAndGetDropOp inspects keys during a drop operation; any malformed posting key encountered (zero UID, wrong length, unknown type) surfaces wrapped through this error.","commonSituations":"DROP ALL/DROP DATA operations scanning the badger store hitting a corrupt or non-conforming key, or key-encoding version skew across Dgraph versions.","solutions":["Read the wrapped (caused by) error to identify the exact parse rule violated","Hex-dump the reported key and verify its type byte and length","Run badger tooling/backup-restore to address on-disk corruption","Ensure all nodes run a compatible Dgraph version before dropping data"],"exampleFix":"// before: assuming drop op check failed logically\nok, err := x.IsDropOpKey(key)\n// after: unwrap and diagnose\nif err != nil {\n  log.Printf(\"key parse failed: %v\", errors.Unwrap(err))\n  return err\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ok, err := x.IsDropOpKey(key)\nif err != nil {\n  var parseErr error\n  if errors.Unwrap(err) != nil { parseErr = errors.Unwrap(err) }\n  log.Printf(\"drop-op key check failed for %x: %v (cause: %v)\", key, err, parseErr)\n  return fmt.Errorf(\"aborting drop: %w\", err)\n}","preventionTips":["Log hex dumps of failing keys before aborting drop operations","Run backups/restores through badger tooling to detect corruption","Keep all Dgraph nodes version-aligned during DROP operations"],"tags":["go","badger","key-parsing","drop-op"],"backgroundTag":"malformed-key-length","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}