unionlabs/union · error

error while creating a new delegation period record: %w

Error message

error while creating a new delegation period record: %w

What it means

Companion to the BeforeDelegationCreated panic in uniond export: after each delegation is re-created, AfterDelegationModified is replayed to write the new delegation-period record. The comment again notes the stock hook always returns nil, so the panic guards only against a distribution keeper whose hook implementation returns an error during export.

Source

Thrown at uniond/app/export.go:158

		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
		}
		err = app.StakingKeeper.SetRedelegation(ctx, red)
		if err != nil {
			panic(err)
		}
		return false

View on GitHub (pinned to 031785bb6d)

Solutions

  1. Reproduce with the stock uniond binary — if it does not panic, the cause is your build's hook overrides
  2. Audit everything wrapped around app.DistrKeeper.Hooks() for error returns
  3. Pin/align the vendored cosmos-sdk version
  4. In forks, keep these hooks returning nil during export or replace the panics with explicit error handling
Defensive patterns

Strategy: validation

Validate before calling

# Confirm the distr hooks your build will replay are the stock nil-returning ones
grep -rn "AfterDelegationModified" $(go env GOMODCACHE)/github.com/cosmos/cosmos-sdk@*/x/distribution/keeper/hooks.go | head

Prevention

When it happens

Trigger: uniond export with a custom DistrKeeper/hooks wrapper whose AfterDelegationModified returns a non-nil error, or SDK behavior drift after a version bump. On an unmodified build with the vendored SDK this path does not execute.

Common situations: Forked hook middleware that validates delegations; SDK upgrades altering hook contracts; test setups injecting erroring hooks.

Related errors


AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16). Data as JSON: /api/errors/cd43a22d4fbdd4d5. Report an issue: GitHub.