{"record":{"id":"7f9a75e619efa418","repo":"yorukot/superfile","slug":"dimensions-must-be-positive-maxwidth-d-maxheigh-7f9a75","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/kitty.go","lineNumber":80,"sourceCode":"\n// KittyImageResult holds both the placeholder string for the cell buffer\n// and the raw transmission data to send directly to the terminal.\ntype KittyImageResult struct {\n\t// Placeholders is the Unicode placeholder string for embedding in the view.\n\t// It contains kitty.Placeholder characters with diacritics.\n\tPlaceholders string\n\t// RawTransmit is the Kitty graphics APC data to send via tea.Raw().\n\t// It transmits the image data to the terminal out-of-band.\n\tRawTransmit string\n}\n\n// renderWithKittyUsingTermCap renders an image using Kitty graphics protocol\n// with Unicode virtual placeholders (compatible with cell-based renderers).\nfunc (p *ImagePreviewer) renderWithKittyUsingTermCap(img image.Image, path string,\n\toriginalWidth, originalHeight, maxWidth, maxHeight int, _ int,\n) (*KittyImageResult, error) {\n\tif maxWidth <= 0 || maxHeight <= 0 {\n\t\treturn nil, fmt.Errorf(\"dimensions must be positive (maxWidth=%d, maxHeight=%d)\", maxWidth, maxHeight)\n\t}\n\n\tcellSize := p.terminalCap.GetTerminalCellSize()\n\tpixelsPerColumn := cellSize.PixelsPerColumn\n\tpixelsPerRow := cellSize.PixelsPerRow\n\n\tslog.Debug(\"pixelsPerColumn\", \"pixelsPerColumn\", pixelsPerColumn, \"pixelsPerRow\", pixelsPerRow)\n\n\timgRatio := float64(originalWidth) / float64(originalHeight)\n\ttermRatio := float64(maxWidth*pixelsPerColumn) / float64(maxHeight*pixelsPerRow)\n\n\tvar dstCols, dstRows int\n\tif imgRatio > termRatio {\n\t\tdstCols = maxWidth\n\t\tdstRows = int(float64(dstCols*pixelsPerColumn) / imgRatio / float64(pixelsPerRow))\n\t} else {\n\t\tdstRows = maxHeight\n\t\tdstCols = int(float64(dstRows*pixelsPerRow) * imgRatio / float64(pixelsPerColumn))","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/pkg/file_preview/kitty.go#L62-L98","documentation":"This error is thrown by the Kitty graphics-protocol image renderer when the caller supplies a non-positive maxWidth or maxHeight. The renderer needs a positive cell budget to compute the scaled destination grid (dstCols/dstRows), so it fails fast before querying terminal cell size. It is a caller-contract violation, not an environment failure.","triggerScenarios":"Calling ImagePreviewWithRenderer (which calls renderWithKittyUsingTermCap) with maxWidth<=0 or maxHeight<=0 — e.g. a preview pane that was never laid out, a width/height computed from a zero-size terminal, or an off-by-one subtraction like width-1 on a 1-column pane producing 0.","commonSituations":"TUI apps rendering previews before the first WindowSizeEvent arrives; panes collapsed to zero width; tests constructing an ImagePreviewer without setting dimensions; integer truncation from dividing terminal size by a splitter factor yielding 0.","solutions":["Ensure the preview is only rendered after a real terminal size is known (guard on the WindowSizeEvent / initial layout).","Clamp dimensions to a minimum, e.g. if maxWidth < 1 { maxWidth = 1 }; if maxHeight < 1 { maxHeight = 1 } before calling the renderer.","Skip image rendering when the pane is too small and fall back to the text/file-info preview.","Add a unit test asserting renderWithKittyUsingTermCap is never invoked with non-positive dims."],"exampleFix":"// before\nres, err := previewer.ImagePreviewWithRenderer(img, path, w, h, 0, 0)\n// after\nif w <= 0 || h <= 0 { return nil } // pane not laid out yet\nres, err := previewer.ImagePreviewWithRenderer(img, path, w, h, max(w, 1), max(h, 1))","handlingStrategy":"validation","validationCode":"func canRender(w, h int) bool { return w > 0 && h > 0 }\nif !canRender(previewW, previewH) { return nil } // skip render until layout known","typeGuard":null,"tryCatchPattern":"if res, err := previewer.ImagePreviewWithRenderer(img, path, w, h); err != nil {\n    if strings.Contains(err.Error(), \"dimensions must be positive\") {\n        return nil // pane not laid out; retry on next size event\n    }\n    return err\n}","preventionTips":["Only render previews after the first terminal resize/layout event delivers real dimensions.","Clamp width/height to at least 1 before calling any renderer.","Add a regression test for zero-size pane inputs.","Log dimensions once at render time to catch layout bugs early."],"tags":["kitty","image-preview","validation","terminal"],"backgroundTag":"invalid-preview-dimensions","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}