crowdsecurity/crowdsec · error

no hub configuration provided

Error message

no hub configuration provided

What it means

NewHub constructs the cwhub Hub object and throws 'no hub configuration provided' when its *csconfig.LocalHubCfg argument is nil. The Hub cannot know where to read its index or item directories without local config, so construction fails immediately.

Source

Thrown at pkg/cwhub/hub.go:43

	Warnings []string // Warnings encountered during sync
}

// GetDataDir returns the data directory, where data sets are installed.
// Empty for a hub created without local configuration (e.g. zero-value Hub in tests).
func (h *Hub) GetDataDir() string {
	if h.local == nil {
		return ""
	}

	return h.local.InstallDataDir
}

// NewHub returns a new Hub instance with local and (optionally) remote configuration.
// The hub is not synced automatically. Load() must be called to read the index, sync the local state,
// and check for unmanaged items.
func NewHub(local *csconfig.LocalHubCfg, logger *logrus.Logger) (*Hub, error) {
	if local == nil {
		return nil, errors.New("no hub configuration provided")
	}

	if logger == nil {
		logger = logrus.New()
		logger.SetOutput(io.Discard)
	}

	hub := &Hub{
		local:  local,
		logger: logger,
	}

	return hub, nil
}

// Load reads the state of the items on disk.
func (h *Hub) Load() error {
	h.logger.Debugf("loading hub idx %s", h.local.HubIndexFile)

View on GitHub (pinned to 909b515798)

Solutions

  1. Load and validate configuration before constructing the hub (cfg.LoadCrowdsecConfig / load the api.server section)
  2. Pass a non-nil *csconfig.LocalHubCfg (e.g. cfg.Crowdsec.API.Server.Hub) to NewHub
  3. In code, nil-check the config before calling NewHub and return a clearer configuration error

Example fix

// before
hub, err := cwhub.NewHub(nil, logger)
// after
if localCfg == nil {
    return fmt.Errorf("hub configuration missing; check config.yaml api.server section")
}
hub, err := cwhub.NewHub(localCfg, logger)
Defensive patterns

Strategy: validation

Validate before calling

if localCfg == nil { return errors.New("hub configuration missing: load config before cwhub.NewHub") }

Type guard

func hubCfgReady(cfg *csconfig.Config) bool { return cfg != nil && cfg.Crowdsec != nil && cfg.Crowdsec.API != nil && cfg.Crowdsec.API.Server != nil && cfg.Crowdsec.API.Server.Hub != nil }

Try / catch

hub, err := cwhub.NewHub(localCfg, logger)
if err != nil { return fmt.Errorf("failed to create hub: %w", err) }

Prevention

When it happens

Trigger: Calling cwhub.NewHub(nil, logger) directly, or via callers (update, Hub, Serve, hubWithConfigs) when the LocalHubCfg was never built from config because the 'api.server' / hub config section is missing.

Common situations: Programmatic use of cwhub without loading csconfig first; loading a truncated/empty crowdsec config file so the hub section is absent; tools that call Hub before config load.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/3370281c18062f77. Report an issue: GitHub.