From 5e0b91461ff4ac585dc78ac7a168bfeca7fcaf4f Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Mon, 29 Aug 2022 21:21:25 +0200 Subject: [PATCH] Unify cache_ctx wraps (#2519) * Unify cache_ctx wraps * Apply matt suggested fix --- osmoutils/cache_ctx.go | 2 ++ x/epochs/types/hooks.go | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/osmoutils/cache_ctx.go b/osmoutils/cache_ctx.go index db93d188902..60b382236ca 100644 --- a/osmoutils/cache_ctx.go +++ b/osmoutils/cache_ctx.go @@ -29,6 +29,8 @@ func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err err } else { // no error, write the output of f write() + // Temporary, should be removed once: https://github.com/cosmos/cosmos-sdk/issues/12912 + ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) } return err } diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index aa4cc3e4d7a..e54367b14f5 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -1,6 +1,8 @@ package types import ( + fmt "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/v11/osmoutils" @@ -42,13 +44,13 @@ func panicCatchingEpochHook( epochIdentifier string, epochNumber int64, ) { - defer func() { - if recovErr := recover(); recovErr != nil { - osmoutils.PrintPanicRecoveryError(ctx, recovErr) - } - }() - cacheCtx, write := ctx.CacheContext() - hookFn(cacheCtx, epochIdentifier, epochNumber) - write() - ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) + wrappedHookFn := func(ctx sdk.Context) error { + hookFn(ctx, epochIdentifier, epochNumber) + return nil + } + // TODO: Thread info for which hook this is, may be dependent on larger hook system refactoring + err := osmoutils.ApplyFuncIfNoError(ctx, wrappedHookFn) + if err != nil { + ctx.Logger().Error(fmt.Sprintf("error in epoch hook %v", err)) + } }