{"record":{"id":"e0d92a27b573a2c4","repo":"crowdsecurity/crowdsec","slug":"unable-to-create-folder-s-w-e0d92a","errorCode":null,"errorMessage":"unable to create folder '%s': %w","messagePattern":"unable to create folder '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest_item.go","lineNumber":639,"sourceCode":"\n\t// copy template profile file to runtime folder\n\tif err = Copy(t.TemplateProfilePath, t.RuntimeProfileFilePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateProfilePath, t.RuntimeProfileFilePath, err)\n\t}\n\n\t// copy template simulation file to runtime folder\n\tif err = Copy(t.TemplateSimulationPath, t.RuntimeSimulationFilePath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateSimulationPath, t.RuntimeSimulationFilePath, err)\n\t}\n\n\t// copy template patterns folder to runtime folder\n\tif err = CopyDir(patternDir, t.RuntimePatternsPath); err != nil {\n\t\treturn fmt.Errorf(\"unable to copy 'patterns' from '%s' to '%s': %w\", patternDir, t.RuntimePatternsPath, err)\n\t}\n\n\t// create the appsec-configs dir\n\tif err = os.MkdirAll(filepath.Join(t.RuntimePath, \"appsec-configs\"), os.ModePerm); err != nil {\n\t\treturn fmt.Errorf(\"unable to create folder '%s': %w\", t.RuntimePath, err)\n\t}\n\n\t// if it's an appsec rule test, we need acquis and appsec profile\n\tif len(t.Config.AppsecRules) > 0 {\n\t\t// copy template acquis file to runtime folder\n\t\tlog.Debugf(\"copying %s to %s\", t.TemplateAcquisPath, t.RuntimeAcquisFilePath)\n\n\t\tif err = Copy(t.TemplateAcquisPath, t.RuntimeAcquisFilePath); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateAcquisPath, t.RuntimeAcquisFilePath, err)\n\t\t}\n\n\t\tlog.Debugf(\"copying %s to %s\", t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, \"appsec-configs\", \"config.yaml\"))\n\t\t// copy template appsec-config file to runtime folder\n\t\tif err = Copy(t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, \"appsec-configs\", \"config.yaml\")); err != nil {\n\t\t\treturn fmt.Errorf(\"unable to copy '%s' to '%s': %w\", t.TemplateAppsecProfilePath, filepath.Join(t.RuntimePath, \"appsec-configs\", \"config.yaml\"), err)\n\t\t}\n\t} else { // otherwise we drop a blank acquis file\n\t\tif err = os.WriteFile(t.RuntimeAcquisFilePath, []byte(\"\"), os.ModePerm); err != nil {","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest_item.go#L621-L657","documentation":"This error is returned by HubTestItem.Run when os.MkdirAll fails to create the appsec-configs directory under the test runtime path. Note the message reports t.RuntimePath rather than the exact subdirectory being created; the wrapped error is the OS-level mkdir failure (permission, existing non-directory file, etc.).","triggerScenarios":"HubTestItem.Run is called and a file named 'appsec-configs' already exists at filepath.Join(t.RuntimePath, \"appsec-configs\"), or the runtime directory is unwritable, or the filesystem is full/read-only.","commonSituations":"Leftover runtime folder where a previous run created appsec-configs as something other than a directory; running tests as a user without write access to the runtime path; read-only CI artifact mount or full disk.","solutions":["Delete the stale runtime directory (t.RuntimePath) and re-run the test so directories are recreated cleanly.","Check whether 'appsec-configs' exists as a plain file in the runtime path and remove it.","Verify the current user has write permission on t.RuntimePath.","Check disk space / read-only mount status."],"exampleFix":"// before\nitem.Run(ctx, patternDir) // \"unable to create folder ...: mkdir ...: file exists\"\n// after: clean runtime before running\nos.RemoveAll(item.RuntimePath)\nif err := item.Run(ctx, patternDir); err != nil { ... }","handlingStrategy":"validation","validationCode":"p := filepath.Join(item.RuntimePath, \"appsec-configs\")\nif fi, err := os.Stat(p); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory; remove it\", p)\n}\nos.RemoveAll(item.RuntimePath) // or ensure clean state","typeGuard":null,"tryCatchPattern":"if err := item.Run(ctx, patternDir); err != nil {\n    if errors.Is(errors.Unwrap(err), syscall.EEXIST) || os.IsPermission(errors.Unwrap(err)) {\n        os.RemoveAll(item.RuntimePath)\n        return item.Run(ctx, patternDir) // one clean retry\n    }\n    return err\n}","preventionTips":["Always start from a clean runtime directory per test run.","Never put a plain file named appsec-configs in the runtime path.","Grant the test user write access to the runtime root.","Monitor disk space and read-only mounts in CI runners."],"tags":["go","mkdir","hubtest","filesystem"],"backgroundTag":"mkdir-permission-denied","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"}