CadQuery / CadQuery/CQ-editor

to_compound raises IndexError for an empty list

Open
#600 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.2k
Forks
210
PR merge metrics
No merged PRs in 30d

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:

```python
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](https://github.com/CadQuery/CQ-editor/issues/211) and [#261](https://github.com/CadQuery/CQ-editor/issues/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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.