{"record":{"id":"9ce0817d92cbb8ca","repo":"Comfy-Org/ComfyUI","slug":"cannot-create-grid-from-empty-image-list","errorCode":null,"errorMessage":"Cannot create grid from empty image list","messagePattern":"Cannot create grid from empty image list","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_dataset.py","lineNumber":1671,"sourceCode":"        ),\n        io.Int.Input(\n            \"cell_height\",\n            default=256,\n            min=32,\n            max=2048,\n            tooltip=\"Height of each cell in the grid.\",\n            advanced=True,\n        ),\n        io.Int.Input(\n            \"padding\", default=4, min=0, max=50, tooltip=\"Padding between images.\", advanced=True\n        ),\n    ]\n\n    @classmethod\n    def _group_process(cls, images, columns, cell_width, cell_height, padding):\n        \"\"\"Arrange images into a grid.\"\"\"\n        if len(images) == 0:\n            raise ValueError(\"Cannot create grid from empty image list\")\n\n        # Calculate grid dimensions\n        num_images = len(images)\n        rows = (num_images + columns - 1) // columns  # Ceiling division\n\n        # Calculate total grid size\n        grid_width = columns * cell_width + (columns - 1) * padding\n        grid_height = rows * cell_height + (rows - 1) * padding\n\n        # Create blank grid\n        grid = Image.new(\"RGB\", (grid_width, grid_height), (0, 0, 0))\n\n        # Place images\n        for idx, img_tensor in enumerate(images):\n            row = idx // columns\n            col = idx % columns\n\n            # Convert to PIL and resize to cell size","sourceCodeStart":1653,"sourceCodeEnd":1689,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_dataset.py#L1653-L1689","documentation":"Thrown by the grid-layout helper when the incoming image list is empty: a grid of zero images has no dimensions, so the node refuses instead of producing a blank/degenerate image. It fires before any grid math (rows, width, height) runs.","triggerScenarios":"Feeding the grid node an empty image list: an empty batch from an upstream loader (e.g. LoadImage batch of zero, a dataset/loader that filtered out every item, or an empty list literal wired into the input).","commonSituations":"Dataset or directory loaders where a filter (extension, resolution, text match) removed all items; batch-processing pipelines where one iteration legitimately produces zero images; preview/inspection nodes wired to a list that can be empty.","solutions":["Check the upstream node: verify the loader/filter actually produced images (inspect its output count).","Add a conditional in the workflow or wrapper code: skip the grid node when len(images) == 0.","Loosen or fix the upstream filter so at least one image survives."],"exampleFix":"# before\ngrid = node._group_process(images, columns=4, cell_width=256, cell_height=256, padding=4)\n# after\nif not images:\n    raise ValueError('upstream loader returned no images; check its filter')\ngrid = node._group_process(images, columns=4, cell_width=256, cell_height=256, padding=4)","handlingStrategy":"validation","validationCode":"if not images:\n    raise ValueError('upstream loader returned 0 images; fix the loader/filter before building a grid')","typeGuard":"def has_images(imgs: list) -> bool:\n    return len(imgs) > 0","tryCatchPattern":null,"preventionTips":["Wire the grid node only after a loader whose filter you have verified produces at least one image.","In batch pipelines, skip the grid step for empty batches instead of letting the node fail.","Log image counts right after filtering stages."],"tags":["comfyui","validation","empty-input","image"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}