fix unit tests and error messages

This commit is contained in:
Elijah Duffy
2025-06-04 14:03:53 -07:00
parent c3c8a2cafc
commit 76d6216a9c
3 changed files with 137 additions and 117 deletions

View File

@@ -87,6 +87,9 @@ func (app *Lifecycle) WithLogger(logger *slog.Logger) *Lifecycle {
// Logger returns the logger for the lifecycle.
func (app *Lifecycle) Logger() *slog.Logger {
if app == nil {
panic("lifecycle is nil, cannot get logger")
}
if app.opts.Logger == nil {
app.opts.Logger = slog.Default()
}
@@ -182,12 +185,16 @@ func (app *Lifecycle) require(logger *slog.Logger, unique bool, modules ...*Modu
// Check if the module has already been set up
if _, ok := app.setupTracker[mod.name]; ok {
if unique {
return fmt.Errorf("module %s is already set up, cannot require it again", mod)
return fmt.Errorf("module %s is already set up, cannot require again", mod)
}
app.Logger().Warn("module already set up, ignoring", "module", mod)
// Mark duplicate module as loaded
mod.loaded = true
mod.lifecycle = app
mod.logger = logger
continue
}