Skip to content

Raise a clear error for height-field generators without an origin - #8936

Open
dfloreaa wants to merge 2 commits into
isaac-sim:mainfrom
dfloreaa:fix/hf-generator-return-contract-error
Open

dfloreaa wants to merge 2 commits into
isaac-sim:mainfrom
dfloreaa:fix/hf-generator-return-contract-error

Conversation

@dfloreaa

@dfloreaa dfloreaa commented Nov 4, 2026 •

Copy link
Copy Markdown

Description

Since #4470, a function decorated with height_field_to_mesh must return the height field together with the terrain origin, and the decorator unpacks the result directly:

z_gen, origin = func(difficulty, cfg)

A custom generator written against the previous contract returns only the height field, so terrain generation fails inside the decorator with

ValueError: too many values to unpack (expected 2)

The error names neither the generator nor the contract change, and it comes after the decorator has already shrunk cfg.size for the generator without restoring it. We hit this with downstream height-field generators when moving a project from release/3.0.0-beta2 to main.

This turns a failure to unpack the generator's result into a TypeError that names the generator and the expected (height_field, origin) return. Any two-item return that unpacked before, such as a list, still works. The decorator now restores cfg.size in a finally block, so the size is also restored when the generator or the border assignment raises. The decorator's docstring now lists both errors it raises in a Raises: section. Generators that already return a tuple are unchanged, which covers all six built-in height-field terrains.

release/3.0.0 does not contain #4470, so no backport is needed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Testing

  • Added test_height_field_generator_without_origin_raises_type_error to test/terrains/test_terrain_generator.py: a decorated generator that returns only the height field must raise the TypeError and leave cfg.size unchanged. It fails on main with the ValueError above and passes with the fix.
  • The whole test_terrain_generator.py passes locally (28 passed).
  • uv run isaaclab --format passes, including the changelog-fragment check.

Since isaac-sim#4470, height_field_to_mesh requires generators to return
(height_field, origin). A generator that still returns only the height
field failed inside the decorator with "ValueError: too many values to
unpack (expected 2)", which names neither the generator nor the contract
change, and left cfg.size shrunk.

Check the generator's return value; if it is not a 2-tuple, restore
cfg.size and raise a TypeError that names the generator and the expected
(height_field, origin) return.

Signed-off-by: Daniel Florea <daniel.florea@tum.de>
@dfloreaa
dfloreaa requested a review from a team November 4, 2026 13:48
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Nov 4, 2026
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR gives custom height-field generators a clearer error when they omit the origin.

  • Height-field generators get a clear error when they omit the terrain origin.

Reviews (1) · Last reviewed commit: "Raise a clear error for height-field gen..." · Reviewed by Greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

Needs attention: Design and architecture (1), Compatibility and deprecation (1), Test quality (1). Other reviewed categories look good.

  • PR description: The body matches the guard, documentation, changelog, and regression test, but “non-breaking” is inaccurate because the tuple-only check rejects previously accepted two-item iterables; disclose that narrowing.
  • Design and architecture: The new exceptional restore duplicates success-path cleanup and still leaks temporary cfg.size when the generator or border assignment raises; restore it once with try/finally.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: Breaking changes: the tuple-only guard rejects two-item lists and other iterable returns previously accepted by unpacking; preserve iterable unpacking or provide a complete deprecation bridge.
  • Implementation: Implementation looks good.
  • Style consistency: Style consistency looks good.
  • Test quality: The regression test covers the error and restored size, but its unused pixel calculations repeat production logic; return any array directly and remove the extra import.

Minor fixes needed. Posted 3 inline findings.

Automated review; human maintainers own approval decisions.

Address review feedback on the height-field return check:

- Unpack the generator's result and turn only an unpacking failure into
  the TypeError, so two-item iterables such as lists keep working as
  before instead of being rejected by a tuple check.
- Restore cfg.size once in a finally block, which also covers a
  generator that raises and a failing border assignment.
- Drop the unused shape setup from the regression test.

Signed-off-by: Daniel Florea <daniel.florea@tum.de>

@AntoineRichard AntoineRichard left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @dfloreaa LGTM!

@AntoineRichard

Copy link
Copy Markdown
Collaborator

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants