crowdsecurity/crowdsec · error
while serializing ConsoleConfig (for %s): %w
Error message
while serializing ConsoleConfig (for %s): %w
What it means
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'.
Source
Thrown at pkg/csconfig/crowdsec_service.go:169
c.Crowdsec.BucketsRoutinesCount = 1
}
if c.Crowdsec.OutputRoutinesCount <= 0 {
c.Crowdsec.OutputRoutinesCount = 1
}
if err = c.LoadAPIClient(); err != nil {
return fmt.Errorf("loading api client: %w", err)
}
return nil
}
func (c *CrowdsecServiceCfg) DumpContextConfigFile() error {
// XXX: MakeDirs
out, err := yaml.Marshal(c.ContextToSend)
if err != nil {
return fmt.Errorf("while serializing ConsoleConfig (for %s): %w", c.ConsoleContextPath, err)
}
if err = os.MkdirAll(filepath.Dir(c.ConsoleContextPath), 0o700); err != nil {
return fmt.Errorf("while creating directories for %s: %w", c.ConsoleContextPath, err)
}
if err := os.WriteFile(c.ConsoleContextPath, out, 0o600); err != nil {
return fmt.Errorf("while dumping console config to %s: %w", c.ConsoleContextPath, err)
}
log.Infof("%s file saved", c.ConsoleContextPath)
return nil
}
View on GitHub (pinned to 909b515798)
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
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := yaml.Marshal(cfg.Crowdsec.ContextToSend); err != nil { log.Warnf("context not serializable: %v", err) } Type guard
if v, ok := ctx[key].(string); ok { ContextToSend[key] = v } Try / catch
if err := cfg.Crowdsec.DumpContextConfigFile(); err != nil { log.Errorf("could not dump console context: %v", err) } Prevention
- 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
When it happens
Trigger: Calling DumpContextConfigFile with a ContextToSend map that cannot be YAML-serialized (unsupported value types, e.g. channels/funcs or cyclic structures injected programmatically).
Common situations: Rare in practice: usually only hit by plugins/overrides setting non-serializable values into ContextToSend, or by custom code reusing CrowdsecServiceCfg.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- unable to serialize overrides: %w
- no appsec_config provided
- VictoriaLogs url is mandatory
- VictoriaLogs query is mandatory
- empty file
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/49730cf7705cef33.
Report an issue: GitHub.