Skip to content

BUG: report missing impact roots explicitly #1147

Description

@ting-hong-shieh

Describe the bug

Flight.__handle_impact_event() assumes that cubic interpolation always returns exactly one valid root in the current solver step. It already reports multiple valid roots explicitly, but it indexes an empty list when no valid root is found.

The resulting exception does not identify the failed numerical operation:

IndexError: list index out of range

To reproduce

At cb6106a717207dd8fc2dfe1446d80ff75022f21b, make find_roots_cubic_function() return roots outside the open solver interval, such as [-1 + 0j, 2 + 0j] for a one-second step, and call the impact event handler. valid_t_root is empty and valid_t_root[0] raises IndexError.

Expected behavior

The impact handler should report the failed root selection directly, consistent with the existing rail-exit handling:

ValueError: No valid roots found when solving for impact time.

The single-root path should remain unchanged, and multiple valid roots should continue to raise the existing ValueError.

Proposed fix

Check for an empty valid_t_root list before indexing it. Add focused tests for zero, one, and multiple valid roots.

Environment

  • Base SHA: cb6106a717207dd8fc2dfe1446d80ff75022f21b
  • RocketPy 1.13.0
  • Python 3.12.6
  • NumPy 2.5.2
  • SciPy 1.18.0
  • pytest 9.1.1
  • macOS 26.5.2, arm64

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