{"record":{"id":"a1174e104c5d5d99","repo":"yorukot/superfile","slug":"dimensions-must-be-positive-maxwidth-d-maxheigh","errorCode":null,"errorMessage":"dimensions must be positive (maxWidth=%d, maxHeight=%d)","messagePattern":"dimensions must be positive \\(maxWidth=(.+?), maxHeight=(.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/file_preview/image_preview.go","lineNumber":72,"sourceCode":"\t\tcache:       cache.New[string](maxEntries, expiration),\n\t\tterminalCap: NewTerminalCapabilities(),\n\t}\n\n\t// Initialize terminal capabilities\n\tpreviewer.terminalCap.InitTerminalCapabilities()\n\n\treturn previewer\n}\n\n// ImagePreview generates a preview of an image file.\n// Returns (render, rawTransmit, error) where rawTransmit is non-empty only\n// for Kitty protocol and should be sent via tea.Raw() to transmit image data\n// directly to the terminal, bypassing the cell-based renderer.\nfunc (p *ImagePreviewer) ImagePreview(path string, maxWidth int, maxHeight int,\n\tdefaultBGColor string, sideAreaWidth int) (string, string, error) {\n\t// Validate dimensions\n\tif maxWidth <= 0 || maxHeight <= 0 {\n\t\treturn \"\", \"\", fmt.Errorf(\"dimensions must be positive (maxWidth=%d, maxHeight=%d)\", maxWidth, maxHeight)\n\t}\n\n\t// Create dimensions string for cache key\n\tdimensions := fmt.Sprintf(\"%d,%d,%s,%d\", maxWidth, maxHeight, defaultBGColor, sideAreaWidth)\n\n\t// Try Kitty first as it's more modern\n\tif p.IsKittyCapable() {\n\t\tcacheKey := getPreviewObjKey(path, dimensions, RendererKitty)\n\t\trawKey := cacheKey + \":raw\"\n\n\t\tif preview, exists := p.cache.Get(cacheKey); exists {\n\t\t\tif rawTransmit, rawExists := p.cache.Get(rawKey); rawExists && rawTransmit != \"\" {\n\t\t\t\treturn preview, rawTransmit, nil\n\t\t\t}\n\t\t\t// rawKey evicted or empty — treat as cache miss\n\t\t}\n\n\t\trender, rawTransmit, err := p.ImagePreviewWithRenderer(","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/pkg/file_preview/image_preview.go#L54-L90","documentation":"ImagePreview validates its arguments before doing any work and requires both maxWidth and maxHeight to be strictly positive, since they drive resizing and cache keys. This error is returned immediately when either dimension is zero or negative. It is an argument-validation error, not an image-processing failure.","triggerScenarios":"Calling ImagePreview with maxWidth <= 0 or maxHeight <= 0 — e.g., passing terminal dimensions computed as 0 when the terminal size is unknown, or negative values from unsigned/overflow arithmetic.","commonSituations":"Terminal size not yet measured (0x0) at first render before a WindowSizeMsg arrives; layout math yielding 0 remaining area after fixed panels consume the full width.","solutions":["Guard terminal dimensions before calling: skip preview or use defaults when width/height <= 0","Wait for the terminal size message (e.g., tea.WindowSizeMsg) before rendering previews","Clamp computed dimensions to a minimum of 1","Check layout math that subtracts side panels — it may go negative on tiny terminals"],"exampleFix":"// before\nout, raw, err := previewer.ImagePreview(path, w, h, bg, side)\n// after\nif w <= 0 || h <= 0 {\n\tw, h = 40, 20 // fallback dimensions\n}\nout, raw, err := previewer.ImagePreview(path, w, h, bg, side)","handlingStrategy":"validation","validationCode":"if maxWidth <= 0 || maxHeight <= 0 { skip preview or substitute defaults }","typeGuard":null,"tryCatchPattern":"out, raw, err := previewer.ImagePreview(path, w, h, bg, side)\nif err != nil && strings.Contains(err.Error(), \"dimensions must be positive\") {\n\treturn \"\", \"\", nil // skip preview gracefully\n}","preventionTips":["Only call after receiving terminal size (WindowSizeMsg)","Clamp all computed dimensions to a minimum of 1","Check subtraction-based layout math for negative results","Default unknown terminal size to a sane value (80x24)"],"tags":["go","validation","image","preview"],"backgroundTag":"invalid-argument","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}