charmbracelet/crush · error
failed to create .gitignore file: %q %w
Error message
failed to create .gitignore file: %q %w
What it means
After creating the data directory, createDotCrushDir writes a .gitignore containing "*\n" (mode 0644) so workspace data is never committed. This error wraps os.WriteFile failure for that file, meaning the directory exists but the ignore file could not be created.
Source
Thrown at internal/backend/util.go:17
package backend
import (
"fmt"
"os"
"path/filepath"
)
func createDotCrushDir(dir string) error {
if err := os.MkdirAll(dir, 0o700); err != nil {
return fmt.Errorf("failed to create data directory: %q %w", dir, err)
}
gitIgnorePath := filepath.Join(dir, ".gitignore")
if _, err := os.Stat(gitIgnorePath); os.IsNotExist(err) {
if err := os.WriteFile(gitIgnorePath, []byte("*\n"), 0o644); err != nil {
return fmt.Errorf("failed to create .gitignore file: %q %w", gitIgnorePath, err)
}
}
return nil
}
View on GitHub (pinned to 7944b8e522)
Solutions
- Check whether the quoted .gitignore path collides with an existing directory and remove/rename it.
- Verify write permission on the data directory itself (chmod u+w).
- Check disk quota/remaining space.
- Re-run CreateWorkspace; the .gitignore creation is idempotent (skipped when it already exists).
Defensive patterns
Strategy: validation
Validate before calling
p := filepath.Join(dir, ".gitignore")
if fi, err := os.Stat(p); err == nil && fi.IsDir() {
return fmt.Errorf("%s is a directory, cannot write .gitignore", p)
} Type guard
func IsGitignoreWriteErr(err error) (string, bool) {
var pe *fs.PathError
if errors.As(err, &pe) {
return pe.Path, true
}
return "", false
} Try / catch
if err := createDotCrushDir(dir); err != nil {
var pe *fs.PathError
if errors.As(err, &pe) && errors.Is(pe.Err, fs.ErrPermission) {
os.Chmod(dir, 0o700) // restore write access, then retry once
return createDotCrushDir(dir)
}
return err
} Prevention
- Never create a file or directory named .gitignore inside the data dir.
- Check directory write permission right after MkdirAll.
- Watch for security software that locks newly created files.
- On network filesystems, verify quota before large workspace creation.
When it happens
Trigger: CreateWorkspace -> createDotCrushDir where the directory was created (or already existed) but os.WriteFile(gitIgnorePath, ...) fails — permission denied on the directory, .gitignore exists as a directory, disk full, or the directory was made read-only between creation and write.
Common situations: Antivirus or security software locking new files; a directory literally named .gitignore inside the data dir; quota exhaustion on network filesystems (NFS homes).
Related errors
- error checking file: %w
- error creating directory: %w
- error writing file: %w
- failed to create data directory: %q %w
- failed to create .gitignore file: %q %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/5516b5c58b8d6a4a.
Report an issue: GitHub.