dgraph-io/dgraph · error

could not parse key %s

Error message

could not parse key %s

What it means

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.

Source

Thrown at x/keys.go:625

		}

		if len(k) != 12 {
			return p, errors.Errorf("StartUid length != 8 for key: %q, parsed key: %+v", key, p)
		}

		k = k[4:]
		p.StartUid = binary.BigEndian.Uint64(k)
	default:
		// Some other data type.
		return p, errors.Errorf("Invalid data type")
	}
	return p, nil
}

func IsDropOpKey(key []byte) (bool, error) {
	pk, err := Parse(key)
	if err != nil {
		return false, errors.Wrapf(err, "could not parse key %s", hex.Dump(key))
	}

	if pk.IsData() && ParseAttr(pk.Attr) == "dgraph.drop.op" {
		return true, nil
	}
	return false, nil
}

// These predicates appear for queries that have * as predicate in them.
var starAllPredicateMap = map[string]struct{}{
	"dgraph.type": {},
}

var aclPredicateMap = map[string]struct{}{
	"dgraph.xid":             {},
	"dgraph.password":        {},
	"dgraph.user.group":      {},
	"dgraph.rule.predicate":  {},

View on GitHub (pinned to 759e242be6)

Solutions

  1. Read the wrapped (caused by) error to identify the exact parse rule violated
  2. Hex-dump the reported key and verify its type byte and length
  3. Run badger tooling/backup-restore to address on-disk corruption
  4. Ensure all nodes run a compatible Dgraph version before dropping data

Example fix

// before: assuming drop op check failed logically
ok, err := x.IsDropOpKey(key)
// after: unwrap and diagnose
if err != nil {
  log.Printf("key parse failed: %v", errors.Unwrap(err))
  return err
}
Defensive patterns

Strategy: try-catch

Try / catch

ok, err := x.IsDropOpKey(key)
if err != nil {
  var parseErr error
  if errors.Unwrap(err) != nil { parseErr = errors.Unwrap(err) }
  log.Printf("drop-op key check failed for %x: %v (cause: %v)", key, err, parseErr)
  return fmt.Errorf("aborting drop: %w", err)
}

Prevention

When it happens

Trigger: checkAndGetDropOp inspects keys during a drop operation; any malformed posting key encountered (zero UID, wrong length, unknown type) surfaces wrapped through this error.

Common situations: DROP ALL/DROP DATA operations scanning the badger store hitting a corrupt or non-conforming key, or key-encoding version skew across Dgraph versions.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/839349d4c5a26078. Report an issue: GitHub.