{"record":{"id":"6a099866cdd9b012","repo":"charmbracelet/crush","slug":"create-directory-w","errorCode":null,"errorMessage":"create directory: %w","messagePattern":"create directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/stats.go","lineNumber":751,"sourceCode":"\t\tCSS:              template.CSS(statsCSS),\n\t\tJS:               template.JS(statsJS),\n\t\tHeader:           template.HTML(headerSVG),\n\t\tHeartbit:         template.HTML(heartbitSVG),\n\t\tFooter:           template.HTML(footerSVG),\n\t\tFavicon:          template.URL(\"data:image/svg+xml;base64,\" + base64.StdEncoding.EncodeToString([]byte(heartbitSVG))),\n\t\tGeneratedAt:      stats.GeneratedAt.Format(\"2006-01-02\"),\n\t\tProjectName:      projName,\n\t\tUsername:         username,\n\t}\n\n\tvar buf bytes.Buffer\n\tif err := tmpl.Execute(&buf, data); err != nil {\n\t\treturn fmt.Errorf(\"execute template: %w\", err)\n\t}\n\n\t// Ensure parent directory exists.\n\tif err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {\n\t\treturn fmt.Errorf(\"create directory: %w\", err)\n\t}\n\n\treturn os.WriteFile(path, buf.Bytes(), 0o644)\n}\n","sourceCodeStart":733,"sourceCodeEnd":756,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/stats.go#L733-L756","documentation":"generateHTML wraps an error from os.MkdirAll(filepath.Dir(path), 0o755), which creates the parent directory for the output HTML file before writing it. It fails when the directory cannot be created: permission denied on the target path, a non-directory file already occupying a path component, or an invalid path.","triggerScenarios":"Calling generateHTML with an output path whose parent directory cannot be created — e.g. writing under a root-owned directory without sudo, a file named like the target directory exists, or a malformed path.","commonSituations":"Passing --output to a location like /usr/share/... or another user's home without write permission; the output flag pointing inside a path occupied by a regular file; read-only mount or full disk.","solutions":["Check the wrapped error for the offending path component and errno (EACCES, ENOTDIR).","Write the report to a directory you own (e.g. project dir or ~/), not a protected system path.","Remove/rename any regular file that occupies a directory position in the output path.","Verify the filesystem is writable (not read-only, disk not full)."],"exampleFix":"// before\ncrush stats --html --output /root/reports/stats.html // permission denied\n// after\ncrush stats --html --output ./reports/stats.html","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(path)\nif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dir)\n}\nif err := unix.Access(filepath.Dir(dir), unix.W_OK); err != nil {\n    return fmt.Errorf(\"no write permission for %s\", dir)\n}","typeGuard":null,"tryCatchPattern":"if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {\n    return fmt.Errorf(\"cannot create output directory %s: %w\", filepath.Dir(path), err)\n}","preventionTips":["Write reports to directories you own; avoid system paths like /usr or /root.","Default output paths under the project or user config dir.","Check for a regular file occupying a path component before MkdirAll.","Confirm the filesystem is writable (read-only mounts, disk space)."],"tags":["filesystem","permissions","directory","cli"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}