crowdsecurity/crowdsec · error
unable to create directory '%s': %w
Error message
unable to create directory '%s': %w
What it means
createDirs ensures all configured test directories exist via os.MkdirAll; if creation fails the path and cause are wrapped in this error. It is called when installing parsers, scenarios, postoverflows, appsec rules, and by Run, so it usually fails during test-environment setup.
Source
Thrown at pkg/hubtest/hubtest_item.go:453
err = t.ImprovedLogDisplay(crowdsecLogFile)
if err != nil {
log.Errorf("unable to read crowdsec log file '%s': %s", crowdsecLogFile, err)
}
}
}
if err := crowdsecDaemon.Process.Kill(); err != nil {
return fmt.Errorf("terminating crowdsec daemon: %w", err)
}
return nil
}
func createDirs(dirs []string) error {
for _, dir := range dirs {
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return fmt.Errorf("unable to create directory '%s': %w", dir, err)
}
}
return nil
}
func (t *HubTestItem) RunWithLogFile(ctx context.Context) error {
testPath := filepath.Join(t.HubTestPath, t.Name)
if _, err := os.Stat(testPath); os.IsNotExist(err) {
return fmt.Errorf("test '%s' doesn't exist in '%s', exiting", t.Name, t.HubTestPath)
}
logFile := filepath.Join(testPath, t.Config.LogFile)
logType := t.Config.LogType
dsn := "file://" + logFile
logFileStat, err := os.Stat(logFile)
if err != nil {View on GitHub (pinned to 909b515798)
Solutions
- Check permissions on the parent of the reported directory (ls -ld) and chown/chmod or run as the right user
- Remove any regular file that exists at the reported path so the directory can be created
- Point the test runtime dirs (TESTDIR/DATADIR) at a writable location
- Clean stale test state from a previous run (make clean / rm -rf test runtime dirs)
Example fix
// before os.MkdirAll(dir, os.ModePerm) // fails if parent unwritable // after // run harness with writable dirs: TESTDIR=/tmp/crowdsec-hubtest ./tests/run.sh
Defensive patterns
Strategy: validation
Validate before calling
for _, dir := range dirs {
if parent := filepath.Dir(dir); _, err := os.Stat(parent); err != nil {
return fmt.Errorf("parent %s not accessible: %w", parent, err)
}
} Prevention
- Run tests as a user with write access to TESTDIR/DATADIR
- Ensure the paths are directories, not files, from prior runs
- Use writable temp locations in containers
When it happens
Trigger: os.MkdirAll(dir) fails for any configured dir: parent path not writable, path exists as a file, or disk/permission problems.
Common situations: Running tests as a user without write access to the runtime/hub test directories; a previous run left a file where a directory is expected; read-only container filesystem; TESTDIR/DATADIR pointing into a protected location.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- while creating directories for %s: %w
- while creating %s: %w
- while creating %s: %w
- unable to create folder '%s': %w
- while creating data dir: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/868fbd60d01f6938.
Report an issue: GitHub.