unionlabs/union · error
error while incrementing period: %w
Error message
error while incrementing period: %w
What it means
During `uniond export` (genesis export for zero height), the app re-initializes every delegation by replaying the distribution module's BeforeDelegationCreated hook to rebuild validator periods — logic mirrored from cosmos-sdk's simapp export. The inline comment states the stock hook always returns nil, so this panic is a defensive assertion that only fires if the DistrKeeper's hooks start returning errors (fork or SDK drift).
Source
Thrown at uniond/app/export.go:153
}
if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
panic(err)
}
return false
})
// reinitialize all delegations
for _, del := range dels {
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if err != nil {
panic(err)
}
delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress)
if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
// never called as BeforeDelegationCreated always returns nil
panic(fmt.Errorf("error while incrementing period: %w", err))
}
if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
// never called as AfterDelegationModified always returns nil
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
}
}
// reset context height
ctx = ctx.WithBlockHeight(height)
/* Handle staking state. */
// iterate through redelegations, reset creation height
err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}View on GitHub (pinned to 031785bb6d)
Solutions
- Confirm you are running the stock uniond build — on stock builds this branch is unreachable
- Inspect app.DistrKeeper.Hooks() (and any wrapping hook middleware) for overrides that can return errors
- Align the cosmos-sdk version with the one union vendors, since hook signatures/behavior changed across SDK releases
- If you maintain a fork whose hooks can fail, make them nil-safe for the export path or handle the error instead of panicking
Defensive patterns
Strategy: validation
Validate before calling
# Exercise the export path on a disposable copy before relying on it uniond export --home /backup/union-snapshot --for-zero-height > /dev/null && echo export-ok
Prevention
- Pin the vendored cosmos-sdk version and review hook semantics on every bump
- Avoid overriding distribution hooks in forks; if you must, keep them returning nil during export
- Run uniond export regularly in CI against a fixture state so hook drift is caught early
- Treat this panic as a signal your build's keeper behavior diverged from stock, not as data corruption
When it happens
Trigger: Running uniond export on a build where app.DistrKeeper.Hooks().BeforeDelegationCreated can return a non-nil error: a custom distribution keeper override adding validation, or a cosmos-sdk version upgrade that changes hook semantics.
Common situations: Forks that add error paths to distribution hooks; vendored cosmos-sdk version bumped without re-auditing export assumptions; test harnesses that inject failing hooks.
Related errors
- error while creating a new delegation period record: %w
- expected validator, not found
- failed to read upgrade info from disk %s
- newValAddr is not of type bytes.HexBytes
- newValPubKey is not of type crypto.PubKey
AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16).
Data as JSON: /api/errors/e3f91d8c58939ffe.
Report an issue: GitHub.