add additional logging to Module.RequireLoaded
This commit is contained in:
15
module.go
15
module.go
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ErrModuleNotFound is returned when a module is not found in the lifecycle.
|
||||
@@ -62,13 +63,19 @@ func (s *Module) Loaded() bool {
|
||||
return s.loaded
|
||||
}
|
||||
|
||||
// RequireLoaded panics if the module is not loaded.
|
||||
func (s *Module) RequireLoaded() {
|
||||
// RequireLoaded panics if the module is not loaded. Any arguments are included
|
||||
// in the panic message for additional context.
|
||||
func (s *Module) RequireLoaded(msg ...string) {
|
||||
ctx := ""
|
||||
if len(msg) > 0 {
|
||||
ctx = ": " + strings.Join(msg, ", ")
|
||||
}
|
||||
|
||||
if s == nil {
|
||||
panic("module is nil")
|
||||
panic("module is nil" + ctx)
|
||||
}
|
||||
|
||||
if !s.loaded {
|
||||
panic(fmt.Sprintf("module %s not loaded", s.name))
|
||||
panic(fmt.Sprintf("module %s not loaded", s.name) + ctx)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user