From 9087b68651ac2d67b7fb81cc9b1d051afb6a3507 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 6 Oct 2024 22:51:39 +0300 Subject: [PATCH] remind users to call e.Next() in the OnBootstrap hook if the app is still not initilized after the hook trigger --- core/base.go | 10 +++++++++- examples/base/main.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/base.go b/core/base.go index 8265e054..2ac42898 100644 --- a/core/base.go +++ b/core/base.go @@ -381,7 +381,7 @@ func (app *BaseApp) Bootstrap() error { event := &BootstrapEvent{} event.App = app - return app.OnBootstrap().Trigger(event, func(e *BootstrapEvent) error { + err := app.OnBootstrap().Trigger(event, func(e *BootstrapEvent) error { // clear resources of previous core state (if any) if err := app.ResetBootstrapState(); err != nil { return err @@ -421,6 +421,14 @@ func (app *BaseApp) Bootstrap() error { return nil }) + + // add a more user friendly message in case users forgot to call + // e.Next() as part of their bootstrap hook + if err == nil && !app.IsBootstrapped() { + app.Logger().Warn("OnBootstrap hook didn't fail but the app is still not bootstrapped - maybe missing e.Next()?") + } + + return err } type closer interface { diff --git a/examples/base/main.go b/examples/base/main.go index 84cae004..f0ad4cef 100644 --- a/examples/base/main.go +++ b/examples/base/main.go @@ -115,6 +115,7 @@ func main() { }, Priority: 999, // execute as latest as possible to allow users to provide their own route }) + if err := app.Start(); err != nil { log.Fatal(err) }