{"record":{"id":"49730cf7705cef33","repo":"crowdsecurity/crowdsec","slug":"while-serializing-consoleconfig-for-s-w","errorCode":null,"errorMessage":"while serializing ConsoleConfig (for %s): %w","messagePattern":"while serializing ConsoleConfig \\(for (.+?)\\): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/crowdsec_service.go","lineNumber":169,"sourceCode":"\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)\n\t}\n\n\tlog.Infof(\"%s file saved\", c.ConsoleContextPath)\n\n\treturn nil\n}\n","sourceCodeStart":151,"sourceCodeEnd":184,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/crowdsec_service.go#L151-L184","documentation":"DumpContextConfigFile serializes ContextToSend (console context data) to YAML before writing it to ConsoleContextPath. If yaml.Marshal fails on the context payload it is wrapped as 'while serializing ConsoleConfig (for %s): %w'.","triggerScenarios":"Calling DumpContextConfigFile with a ContextToSend map that cannot be YAML-serialized (unsupported value types, e.g. channels/funcs or cyclic structures injected programmatically).","commonSituations":"Rare in practice: usually only hit by plugins/overrides setting non-serializable values into ContextToSend, or by custom code reusing CrowdsecServiceCfg.","solutions":["Inspect what was placed into ContextToSend and remove unsupported value types","Marshal the context manually in a test to find the offending key","Upgrade crowdsec if this occurs with stock configuration"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, err := yaml.Marshal(cfg.Crowdsec.ContextToSend); err != nil { log.Warnf(\"context not serializable: %v\", err) }","typeGuard":"if v, ok := ctx[key].(string); ok { ContextToSend[key] = v }","tryCatchPattern":"if err := cfg.Crowdsec.DumpContextConfigFile(); err != nil { log.Errorf(\"could not dump console context: %v\", err) }","preventionTips":["Only put YAML-safe values (strings, numbers, []string) into ContextToSend","Test context dumping in CI with the same data as production","Avoid programmatic mutation of ContextToSend"],"tags":["yaml","serialization"],"backgroundTag":"json-serialization-failed","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"}