{"record":{"id":"e87bbcca65055e54","repo":"crowdsecurity/crowdsec","slug":"while-dumping-console-config-to-s-w","errorCode":null,"errorMessage":"while dumping console config to %s: %w","messagePattern":"while dumping console config to (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/csconfig/crowdsec_service.go","lineNumber":177,"sourceCode":"\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":159,"sourceCodeEnd":184,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/csconfig/crowdsec_service.go#L159-L184","documentation":"Final step of DumpContextConfigFile: os.WriteFile writes the marshaled YAML to ConsoleContextPath with mode 0600. Any write error (permissions, full disk, read-only fs, path is a directory) is wrapped as 'while dumping console config to %s: %w'.","triggerScenarios":"Directory exists but is not writable by the crowdsec user; disk full; ConsoleContextPath points at an existing directory or read-only mount.","commonSituations":"Root-owned /etc/crowdsec while testing as unprivileged user; container with read-only rootfs; disk exhaustion on busy hosts.","solutions":["Check permissions on the target file/directory and the user crowdsec runs as","Verify free disk space and that the filesystem is not read-only","Ensure ConsoleContextPath is a file path, not a directory"],"exampleFix":"// before\n-rw------- root root /etc/crowdsec/console/context.yaml  (crowdsec runs as 'crowdsec')\n// after\nchown crowdsec:crowdsec /etc/crowdsec/console/context.yaml","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(consoleContextPath); err == nil && info.IsDir() { return fmt.Errorf(\"%s is a directory\", consoleContextPath) }","typeGuard":null,"tryCatchPattern":"if err := cfg.Crowdsec.DumpContextConfigFile(); err != nil { if strings.Contains(err.Error(), \"dumping console config\") { log.Errorf(\"console context write failed: %v\", err) } }","preventionTips":["Give the service user write access to the target file's directory","Monitor disk space on hosts running crowdsec","Point ConsoleContextPath at a dedicated writable directory, not a read-only mount"],"tags":["filesystem","permissions","file-write"],"backgroundTag":"file-write-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"}