to_compound raises IndexError for an empty list

Open Beginner friendly
#600 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
desktop

Research direction

Start in cq_editor/cq_utils.py:52-60 and run the provided to_compound([]) reproduction to confirm the indexing failure. Define and document the empty-list result before the first-element access, then add regression coverage for empty, one-element, and multi-element lists and verify the GUI or export path does not raise IndexError.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
1.2k
Forks
210
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CadQuery/CQ-editor

All issues in CadQuery/CQ-editor

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.