{"record":{"id":"42303366f00934ae","repo":"crowdsecurity/crowdsec","slug":"loading-api-client-w","errorCode":null,"errorMessage":"loading api client: %w","messagePattern":"loading api client: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/crowdsec_service.go","lineNumber":159,"sourceCode":"\n\tif err = c.LoadSimulation(); err != nil {\n\t\treturn fmt.Errorf(\"load error (simulation): %w\", err)\n\t}\n\n\tif c.Crowdsec.ParserRoutinesCount <= 0 {\n\t\tc.Crowdsec.ParserRoutinesCount = 1\n\t}\n\n\tif c.Crowdsec.BucketsRoutinesCount <= 0 {\n\t\tc.Crowdsec.BucketsRoutinesCount = 1\n\t}\n\n\tif c.Crowdsec.OutputRoutinesCount <= 0 {\n\t\tc.Crowdsec.OutputRoutinesCount = 1\n\t}\n\n\tif err = c.LoadAPIClient(); err != nil {\n\t\treturn fmt.Errorf(\"loading api client: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (c *CrowdsecServiceCfg) DumpContextConfigFile() error {\n\t// XXX: MakeDirs\n\tout, err := yaml.Marshal(c.ContextToSend)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while serializing ConsoleConfig (for %s): %w\", c.ConsoleContextPath, err)\n\t}\n\n\tif err = os.MkdirAll(filepath.Dir(c.ConsoleContextPath), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"while creating directories for %s: %w\", c.ConsoleContextPath, err)\n\t}\n\n\tif err := os.WriteFile(c.ConsoleContextPath, out, 0o600); err != nil {\n\t\treturn fmt.Errorf(\"while dumping console config to %s: %w\", c.ConsoleContextPath, err)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/crowdsec_service.go#L141-L177","documentation":"LoadCrowdsec calls LoadAPIClient to validate/prepare the local API client section of the config. Any failure inside (bad LAPI URL, missing credentials, unreadable config) is wrapped as 'loading api client: %w'.","triggerScenarios":"api.client section present but invalid: malformed lapi_url, missing/incorrect credentials file (lapi credentials yaml), or internal LoadAPIClient error during LoadCrowdsec.","commonSituations":"Users register with `cscli lapi register` then move/lose local_api_credentials.yaml; wrong api_url port; YAML indentation mistakes in the api section.","solutions":["Verify api.client.lapi_url and credentials file path in your crowdsec config","Re-run `cscli lapi register` to regenerate local_api_credentials.yaml","Validate the api section YAML syntax and restart"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var creds map[string]string; if b, err := os.ReadFile(lapiCredsPath); err == nil { if err := yaml.Unmarshal(b, &creds); err != nil { log.Fatalf(\"LAPI credentials file invalid: %v\", err) } }","typeGuard":null,"tryCatchPattern":"if err := cfg.LoadCrowdsec(); err != nil { if strings.Contains(err.Error(), \"loading api client\") { log.Fatalf(\"API client config problem: %v\", err) } }","preventionTips":["Run `cscli lapi register` once and never hand-edit the generated credentials file","Use absolute lapi_url including scheme and port","Validate the api section after every config change"],"tags":["config","api","lapi","startup"],"backgroundTag":"missing-required-config-field","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"}