crowdsecurity/crowdsec · error

DB config is empty

Error message

DB config is empty

What it means

Config guard in NewClient: the *csconfig.DatabaseCfg argument is nil, so no database connection can be configured. Means crowdsec/cscli was invoked without a database section in the configuration (and no --db-less path taken).

Source

Thrown at pkg/database/database.go:69

	if config.MaxOpenConns == 0 {
		config.MaxOpenConns = csconfig.DEFAULT_MAX_OPEN_CONNS
	}

	db.SetMaxOpenConns(config.MaxOpenConns)
	drv := entsql.OpenDB(dbdialect, db)

	return drv, nil
}

func NewClient(ctx context.Context, config *csconfig.DatabaseCfg, logger *log.Entry) (*Client, error) {
	var client *ent.Client

	if logger == nil {
		logger = log.StandardLogger().WithFields(nil)
	}

	if config == nil {
		return nil, errors.New("DB config is empty")
	}

	entLogger := logger.WithField("context", "ent")
	entOpt := ent.Log(entLogger.Debug)

	typ, dia, err := config.ConnectionDialect()
	if err != nil {
		return nil, err // unsupported database caught here
	}

	if config.Type == "sqlite" && config.DbPath != ":memory:" {
		/*if it's the first startup, we want to touch and chmod file*/
		if _, err = os.Stat(config.DbPath); os.IsNotExist(err) {
			f, err := os.OpenFile(config.DbPath, os.O_CREATE|os.O_RDWR, 0o600)
			if err != nil {
				return nil, fmt.Errorf("failed to create SQLite database file %q: %w", config.DbPath, err)
			}

View on GitHub (pinned to 909b515798)

Solutions

  1. Add a valid db_config section to config.yaml (or point -c at a config that has one)
  2. If running LAPI is intended, ensure the apiserver config defines its database settings
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/database/database.go:69 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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