{"record":{"id":"007aca23552f5387","repo":"crowdsecurity/crowdsec","slug":"db-config-is-empty","errorCode":null,"errorMessage":"DB config is empty","messagePattern":"DB config is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/database/database.go","lineNumber":69,"sourceCode":"\tif config.MaxOpenConns == 0 {\n\t\tconfig.MaxOpenConns = csconfig.DEFAULT_MAX_OPEN_CONNS\n\t}\n\n\tdb.SetMaxOpenConns(config.MaxOpenConns)\n\tdrv := entsql.OpenDB(dbdialect, db)\n\n\treturn drv, nil\n}\n\nfunc NewClient(ctx context.Context, config *csconfig.DatabaseCfg, logger *log.Entry) (*Client, error) {\n\tvar client *ent.Client\n\n\tif logger == nil {\n\t\tlogger = log.StandardLogger().WithFields(nil)\n\t}\n\n\tif config == nil {\n\t\treturn nil, errors.New(\"DB config is empty\")\n\t}\n\n\tentLogger := logger.WithField(\"context\", \"ent\")\n\tentOpt := ent.Log(entLogger.Debug)\n\n\ttyp, dia, err := config.ConnectionDialect()\n\tif err != nil {\n\t\treturn nil, err // unsupported database caught here\n\t}\n\n\tif config.Type == \"sqlite\" && config.DbPath != \":memory:\" {\n\t\t/*if it's the first startup, we want to touch and chmod file*/\n\t\tif _, err = os.Stat(config.DbPath); os.IsNotExist(err) {\n\t\t\tf, err := os.OpenFile(config.DbPath, os.O_CREATE|os.O_RDWR, 0o600)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to create SQLite database file %q: %w\", config.DbPath, err)\n\t\t\t}\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/database/database.go#L51-L87","documentation":"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).","triggerScenarios":"Thrown at pkg/database/database.go:69 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a valid db_config section to config.yaml (or point -c at a config that has one)","If running LAPI is intended, ensure the apiserver config defines its database settings"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}