{"record":{"id":"cd43a22d4fbdd4d5","repo":"unionlabs/union","slug":"error-while-creating-a-new-delegation-period-recor","errorCode":null,"errorMessage":"error while creating a new delegation period record: %w","messagePattern":"error while creating a new delegation period record: %w","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"uniond/app/export.go","lineNumber":158,"sourceCode":"\t\treturn false\n\t})\n\n\t// reinitialize all delegations\n\tfor _, del := range dels {\n\t\tvalAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tdelAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress)\n\n\t\tif err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {\n\t\t\t// never called as BeforeDelegationCreated always returns nil\n\t\t\tpanic(fmt.Errorf(\"error while incrementing period: %w\", err))\n\t\t}\n\n\t\tif err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {\n\t\t\t// never called as AfterDelegationModified always returns nil\n\t\t\tpanic(fmt.Errorf(\"error while creating a new delegation period record: %w\", err))\n\t\t}\n\t}\n\n\t// reset context height\n\tctx = ctx.WithBlockHeight(height)\n\n\t/* Handle staking state. */\n\n\t// iterate through redelegations, reset creation height\n\terr = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {\n\t\tfor i := range red.Entries {\n\t\t\tred.Entries[i].CreationHeight = 0\n\t\t}\n\t\terr = app.StakingKeeper.SetRedelegation(ctx, red)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\treturn false","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/unionlabs/union/blob/031785bb6dc6b957c624e62bc64c184409c97d7b/uniond/app/export.go#L140-L176","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forked hook middleware that validates delegations; SDK upgrades altering hook contracts; test setups injecting erroring hooks.","solutions":["Reproduce with the stock uniond binary — if it does not panic, the cause is your build's hook overrides","Audit everything wrapped around app.DistrKeeper.Hooks() for error returns","Pin/align the vendored cosmos-sdk version","In forks, keep these hooks returning nil during export or replace the panics with explicit error handling"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm the distr hooks your build will replay are the stock nil-returning ones\ngrep -rn \"AfterDelegationModified\" $(go env GOMODCACHE)/github.com/cosmos/cosmos-sdk@*/x/distribution/keeper/hooks.go | head","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not wrap DistrKeeper hooks with middleware that can error","Re-run export in CI after any SDK upgrade to catch changed hook contracts","Keep forks' export.go in sync with upstream simapp assumptions","Document any hook that can return an error so operators know export will panic"],"tags":["cosmos-sdk","genesis-export","distribution","panic","golang"],"backgroundTag":null,"analyzedSha":"031785bb6dc6b957c624e62bc64c184409c97d7b","analyzedAt":"2026-08-16T06:24:09.996Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}