Skip to content

to_compound raises IndexError for an empty list #600

Description

@MicroMilo

Summary

to_compound() checks whether the input is a list and then reads obj[0] before handling the empty-list case. Empty selections or empty intermediate results therefore raise IndexError in a GUI conversion path instead of returning a defined empty result or a diagnostic error.

Code path

  • cq_editor/cq_utils.py:52-60: the first list element is read before the empty-list branch.
  • The function is used by object-tree display/export paths that can receive an empty result.

Steps to reproduce

The minimal boundary input is an empty list:

from cq_editor.cq_utils import to_compound

to_compound([])

On the checked source revision this reaches the obj[0] access and raises IndexError.

Expected behavior

An empty list should have an explicit, documented result (for example, an empty compound or a clear conversion error) and should not fail with an indexing exception.

Actual behavior

The function indexes an empty list before it can decide how to represent an empty result.

Existing coverage

Issues #211 and #261 concern other Workplane/export failures, but neither identifies this obj[0] root cause. No exact fix was found.

Suggested fix

Define the empty-list behavior before indexing and add a regression test for an empty selection/export result.

Suggested tests

  • to_compound([]).
  • A normal one-element list.
  • A normal multi-element list.
  • Empty GUI selection or empty export result.

Submitted with Codex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions