crowdsecurity/crowdsec · error

while dumping console config to %s: %w

Error message

while dumping console config to %s: %w

What it means

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'.

Source

Thrown at pkg/csconfig/crowdsec_service.go:177

		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

  1. Check permissions on the target file/directory and the user crowdsec runs as
  2. Verify free disk space and that the filesystem is not read-only
  3. Ensure ConsoleContextPath is a file path, not a directory

Example fix

// before
-rw------- root root /etc/crowdsec/console/context.yaml  (crowdsec runs as 'crowdsec')
// after
chown crowdsec:crowdsec /etc/crowdsec/console/context.yaml
Defensive patterns

Strategy: try-catch

Validate before calling

if info, err := os.Stat(consoleContextPath); err == nil && info.IsDir() { return fmt.Errorf("%s is a directory", consoleContextPath) }

Try / catch

if err := cfg.Crowdsec.DumpContextConfigFile(); err != nil { if strings.Contains(err.Error(), "dumping console config") { log.Errorf("console context write failed: %v", err) } }

Prevention

When it happens

Trigger: Directory exists but is not writable by the crowdsec user; disk full; ConsoleContextPath points at an existing directory or read-only mount.

Common situations: Root-owned /etc/crowdsec while testing as unprivileged user; container with read-only rootfs; disk exhaustion on busy hosts.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/e87bbcca65055e54. Report an issue: GitHub.