dgraph-io/dgraph · critical
no ZeroHooks configured - ensure worker package is imported
Error message
no ZeroHooks configured - ensure worker package is imported or hooks.Enable() is called
What it means
GetHooks returns the configured ZeroHooks, which must be registered either by importing the worker package (which sets them via init) or by explicitly calling hooks.Enable()/SetDefaultZeroHooks. If neither global config nor a default is present, it panics rather than returning nil hooks.
Source
Thrown at hooks/config.go:120
return globalConfig.Load()
}
// SetDefaultZeroHooks registers the fallback ZeroHooks used when embedded mode is
// disabled or Config.ZeroHooks is nil. The worker package calls this from its init.
func SetDefaultZeroHooks(h ZeroHooks) {
defaultZeroHooks.Store(&defaultHooksHolder{hooks: h})
}
// GetHooks returns the active Zero hooks.
// If embedded mode is not enabled, it returns the default hooks implementation.
func GetHooks() ZeroHooks {
if cfg := globalConfig.Load(); cfg != nil && cfg.ZeroHooks != nil {
return cfg.ZeroHooks
}
if h := defaultZeroHooks.Load(); h != nil {
return h.hooks
}
panic("no ZeroHooks configured - ensure worker package is imported or hooks.Enable() is called")
}
View on GitHub (pinned to 759e242be6)
Solutions
- Call hooks.Enable() (or hooks.SetDefaultZeroHooks(...)) during startup before any GetHooks call
- Import the worker package for its init side effect (blank import: _ "your/module/worker")
- In tests, set default hooks in TestMain or a setup fixture
- Ensure the global config with ZeroHooks is loaded before use
Example fix
// before
func main() {
StartWorker() // panics: no ZeroHooks
}
// after
import _ "your/module/worker"
func main() {
hooks.Enable()
StartWorker()
} Defensive patterns
Strategy: try-catch
Validate before calling
if cfg := hooks.GlobalConfig(); cfg == nil || cfg.ZeroHooks == nil {
if !hooks.DefaultsSet() { hooks.Enable() }
} Try / catch
defer func() {
if r := recover(); r != nil {
if strings.Contains(fmt.Sprint(r), "no ZeroHooks configured") {
hooks.Enable()
// retry operation
} else { panic(r) }
}
}() Prevention
- Call hooks.Enable() at process startup before any worker activity
- Blank-import the worker package for its init side effects
- Initialize default hooks in TestMain for test binaries
When it happens
Trigger: Calling GetHooks (directly or via workers like AssignNsIdsOverNetwork) in a binary/test that never imports the worker package and never calls hooks.Enable() or sets a default ZeroHooks.
Common situations: Unit tests exercising hook-consuming code without the worker import, trimming imports to break the init-side-effect registration chain, or new entry points wired before hook initialization.
Related errors
- Unsupported key type: %T
- Internal Server Error - a panic was trapped. This indicates
- task queue hasn't been initialized yet
- Invalid UID with value 0 for key: %v
- StartUid length != 8 for key: %q, parsed key: %+v
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/24e2ec59b3567ef9.
Report an issue: GitHub.