{"record":{"id":"2897010829a49110","repo":"charmbracelet/crush","slug":"error-getting-file-info-w","errorCode":null,"errorMessage":"error getting file info: %w","messagePattern":"error getting file info: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ui/common/common.go","lineNumber":91,"sourceCode":"\treturn image.Rect(minX, minY, maxX, maxY)\n}\n\n// BottomLeftRect returns a new [Rectangle] positioned at the bottom-left within the given area with the\n// specified width and height.\nfunc BottomLeftRect(area uv.Rectangle, width, height int) uv.Rectangle {\n\tminX := area.Min.X\n\tmaxX := minX + width\n\tmaxY := area.Max.Y\n\tminY := maxY - height\n\treturn image.Rect(minX, minY, maxX, maxY)\n}\n\n// IsFileTooBig checks if the file at the given path exceeds the specified size\n// limit.\nfunc IsFileTooBig(filePath string, sizeLimit int64) (bool, error) {\n\tfileInfo, err := os.Stat(filePath)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error getting file info: %w\", err)\n\t}\n\n\tif fileInfo.Size() > sizeLimit {\n\t\treturn true, nil\n\t}\n\n\treturn false, nil\n}\n\n// CopyToClipboard copies the given text to the clipboard using both OSC 52\n// (terminal escape sequence) and native clipboard for maximum compatibility.\n// Returns a command that reports success to the user with the given message.\nfunc CopyToClipboard(text, successMessage string) tea.Cmd {\n\treturn CopyToClipboardWithCallback(text, successMessage, nil)\n}\n\n// CopyToClipboardWithCallback copies text to clipboard and executes a callback\n// before showing the success message.","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/ui/common/common.go#L73-L109","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n// tooBig, err := common.IsFileTooBig(cfg.RelativePath, limit) // RelativePath resolved against wrong cwd\n// after\n// abs := filepath.Join(projectRoot, cfg.RelativePath)\n// if _, err := os.Stat(abs); err != nil { /* handle/skip */ }\n// tooBig, err := common.IsFileTooBig(abs, limit)","handlingStrategy":"try-catch","validationCode":"if info, err := os.Stat(path); err != nil {\n\t// decide: skip (ErrNotExist) or report (ErrPermission, etc.)\n} else if info.Size() > limit {\n\t// known too big without needing IsFileTooBig\n}","typeGuard":null,"tryCatchPattern":"tooBig, err := common.IsFileTooBig(path, limit)\nif err != nil {\n\tif errors.Is(err, os.ErrNotExist) {\n\t\treturn nil // treat vanished file as skippable\n\t}\n\treturn fmt.Errorf(\"cannot stat %s: %w\", path, err)\n}\nif tooBig {\n\treturn fmt.Errorf(\"file %s exceeds %d bytes\", path, limit)\n}","preventionTips":["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"],"tags":["filesystem","os-stat","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}