{"record":{"id":"453ac5b05fcce5c1","repo":"crowdsecurity/crowdsec","slug":"while-creating-data-dir-w","errorCode":null,"errorMessage":"while creating data dir: %w","messagePattern":"while creating data dir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubtest/hubtest.go","lineNumber":111,"sourceCode":"\t\treturn \"\", err\n\t}\n\n\tif f.IsDir() {\n\t\treturn \"\", fmt.Errorf(\"%q is a directory, not a file\", resolved)\n\t}\n\n\treturn resolved, nil\n}\n\nfunc NewHubTest(hubPath string, crowdsecPath string, cscliPath string, isAppsecTest bool) (HubTest, error) {\n\thubPath, err := filepath.Abs(hubPath)\n\tif err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't get absolute path of hub: %w\", err)\n\t}\n\n\tsharedDataDir := filepath.Join(hubPath, \".cache\", \"data\")\n\tif err = os.MkdirAll(sharedDataDir, 0o700); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"while creating data dir: %w\", err)\n\t}\n\n\t// we can't use hubtest without the hub\n\tif _, err = os.Stat(hubPath); os.IsNotExist(err) {\n\t\treturn HubTest{}, fmt.Errorf(\"path to hub '%s' doesn't exist, can't run\", hubPath)\n\t}\n\t// we can't use hubtest without crowdsec binary\n\tif crowdsecPath, err = resolveBinaryPath(crowdsecPath); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't find crowdsec binary: %w\", err)\n\t}\n\n\t// we can't use hubtest without cscli binary\n\tif cscliPath, err = resolveBinaryPath(cscliPath); err != nil {\n\t\treturn HubTest{}, fmt.Errorf(\"can't find cscli binary: %w\", err)\n\t}\n\n\tif isAppsecTest {\n\t\tHubTestPath := filepath.Join(hubPath, \".appsec-tests\")","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubtest/hubtest.go#L93-L129","documentation":"NewHubTest creates <hubPath>/.cache/data with os.MkdirAll (mode 0700) for shared hubtest data. If directory creation fails, it returns 'while creating data dir: <err>' — typically a filesystem permission or I/O problem at that exact path.","triggerScenarios":"os.MkdirAll fails because the hub directory is read-only, owned by another user, an ancestor is a file (not a directory), or the disk is full / mounted noexec-read-only.","commonSituations":"Hub mounted read-only in CI; running hubtest as non-root in a root-owned checkout; a stray file named '.cache' where the directory should be; full disk.","solutions":["Make the hub directory writable by the running user: chown -R $(id -u) <hubPath> or chmod u+w","Check that <hubPath>/.cache is a directory, not a file; remove the stray file and retry","Check the mount options / disk space (df -h, mount | grep hubPath)","Run hubtest with a user that has write access to the hub checkout"],"exampleFix":"// before\n.cache is a stale file -> mkdirall fails\n// after\nrm .cache && mkdir -p .cache/data","handlingStrategy":"validation","validationCode":"dataDir := filepath.Join(hubPath, \".cache\", \"data\")\nif info, err := os.Stat(hubPath); err != nil || !info.IsDir() { return fmt.Errorf(\"hub path invalid\") }\nprobe := filepath.Join(dataDir, \".probe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil { return fmt.Errorf(\"hub not writable: %w\", err) }\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"ht, err := hubtest.NewHubTest(hubPath, ...)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"creating data dir\") { log.Fatalf(\"cannot write %s: %v\", pe.Path, pe.Err) }\n}","preventionTips":["Ensure the hub checkout is writable by the hubtest user","Check that .cache is a directory, not a stale file","Monitor disk space on CI runners","Don't mount the hub read-only when running hubtest"],"tags":["filesystem","permissions","mkdir","hubtest"],"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"}