charmbracelet/crush · error
error getting file info: %w
Error message
error getting file info: %w
What it means
IsFileTooBig stats the file at filePath and compares its size against sizeLimit. This error wraps any os.Stat failure — most commonly os.ErrNotExist, but also permission-denied or path-related errors — so the caller can distinguish 'cannot inspect file' from 'file is too big'.
Source
Thrown at internal/ui/common/common.go:91
return image.Rect(minX, minY, maxX, maxY)
}
// BottomLeftRect returns a new [Rectangle] positioned at the bottom-left within the given area with the
// specified width and height.
func BottomLeftRect(area uv.Rectangle, width, height int) uv.Rectangle {
minX := area.Min.X
maxX := minX + width
maxY := area.Max.Y
minY := maxY - height
return image.Rect(minX, minY, maxX, maxY)
}
// IsFileTooBig checks if the file at the given path exceeds the specified size
// limit.
func IsFileTooBig(filePath string, sizeLimit int64) (bool, error) {
fileInfo, err := os.Stat(filePath)
if err != nil {
return false, fmt.Errorf("error getting file info: %w", err)
}
if fileInfo.Size() > sizeLimit {
return true, nil
}
return false, nil
}
// CopyToClipboard copies the given text to the clipboard using both OSC 52
// (terminal escape sequence) and native clipboard for maximum compatibility.
// Returns a command that reports success to the user with the given message.
func CopyToClipboard(text, successMessage string) tea.Cmd {
return CopyToClipboardWithCallback(text, successMessage, nil)
}
// CopyToClipboardWithCallback copies text to clipboard and executes a callback
// before showing the success message.View on GitHub (pinned to 7944b8e522)
Solutions
- Verify the path exists (os.Stat / ls) and is spelled correctly before calling IsFileTooBig
- Use errors.Is(err, os.ErrNotExist) vs errors.Is(err, os.ErrPermission) on the wrapped error to branch: skip missing files, surface permission problems
- Pass an absolute path or resolve relative paths against the intended working directory
- Re-check the file if it may have been renamed/deleted concurrently and treat the miss as non-fatal
Example fix
// before
// tooBig, err := common.IsFileTooBig(cfg.RelativePath, limit) // RelativePath resolved against wrong cwd
// after
// abs := filepath.Join(projectRoot, cfg.RelativePath)
// if _, err := os.Stat(abs); err != nil { /* handle/skip */ }
// tooBig, err := common.IsFileTooBig(abs, limit) Defensive patterns
Strategy: try-catch
Validate before calling
if info, err := os.Stat(path); err != nil {
// decide: skip (ErrNotExist) or report (ErrPermission, etc.)
} else if info.Size() > limit {
// known too big without needing IsFileTooBig
} Try / catch
tooBig, err := common.IsFileTooBig(path, limit)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil // treat vanished file as skippable
}
return fmt.Errorf("cannot stat %s: %w", path, err)
}
if tooBig {
return fmt.Errorf("file %s exceeds %d bytes", path, limit)
} Prevention
- Use absolute paths resolved against a known project root
- Skip-and-log missing files instead of failing the whole operation when scanning directories
- Re-stat or handle race conditions when files may be deleted concurrently
- Check symlink targets exist before passing symlinked paths
When it happens
Trigger: Calling IsFileTooBig with a path that does not exist, a path where an intermediate directory is missing, a file the process lacks permission to stat, or a broken symlink; also malformed/empty paths.
Common situations: Displaying file contents in the TUI after the file was deleted or renamed on disk; relative path resolved against an unexpected working directory; reading from a removed tmpdir; symlinked files whose target vanished; permission-restricted files.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- error checking file: %w
- failed to read file: %w
- failed to create parent directories: %w
- failed to create output file: %w
- failed to access file: %w
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/2897010829a49110.
Report an issue: GitHub.