summaryrefslogtreecommitdiff
path: root/modules.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-04-13 09:48:54 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-04-13 09:48:54 -0600
commitec456811bb6d61ce32dbe6e4b7580d383f8a4adf (patch)
tree4d49b468e1677584f47262aafa849b43133d6603 /modules.go
parent68cebb28d063a7a71705ce022f118b5e1205fa3f (diff)
core: Don't return error on RegisterModule() and RegisterAdapter()
These functions are called at init-time, and their inputs are hard-coded so there are no environmental or user factors that could make it fail or succeed; the error return values are often ignored, and when they're not, they are usually a fatal error anyway. To ensure that a programmer mistake is not missed, we now panic instead. Last breaking change 🤞
Diffstat (limited to 'modules.go')
-rw-r--r--modules.go19
1 files changed, 9 insertions, 10 deletions
diff --git a/modules.go b/modules.go
index d8d6fdd..584a298 100644
--- a/modules.go
+++ b/modules.go
@@ -125,33 +125,32 @@ type ModuleMap map[string]json.RawMessage
// be properly recorded, this should be called in the
// init phase of runtime. Typically, the module package
// will do this as a side-effect of being imported.
-// This function returns an error if the module's info
-// is incomplete or invalid, or if the module is
-// already registered.
-func RegisterModule(instance Module) error {
+// This function panics if the module's info is
+// incomplete or invalid, or if the module is already
+// registered.
+func RegisterModule(instance Module) {
mod := instance.CaddyModule()
if mod.ID == "" {
- return fmt.Errorf("module ID missing")
+ panic("module ID missing")
}
if mod.ID == "caddy" || mod.ID == "admin" {
- return fmt.Errorf("module ID '%s' is reserved", mod.ID)
+ panic(fmt.Sprintf("module ID '%s' is reserved", mod.ID))
}
if mod.New == nil {
- return fmt.Errorf("missing ModuleInfo.New")
+ panic("missing ModuleInfo.New")
}
if val := mod.New(); val == nil {
- return fmt.Errorf("ModuleInfo.New must return a non-nil module instance")
+ panic("ModuleInfo.New must return a non-nil module instance")
}
modulesMu.Lock()
defer modulesMu.Unlock()
if _, ok := modules[string(mod.ID)]; ok {
- return fmt.Errorf("module already registered: %s", mod.ID)
+ panic(fmt.Sprintf("module already registered: %s", mod.ID))
}
modules[string(mod.ID)] = mod
- return nil
}
// GetModule returns module information from its ID (full name).