Skip to content

narrow except Exception in clothoid path planner and state machine display to specific types#1387

Open
HrachShah wants to merge 2 commits into
AtsushiSakai:masterfrom
HrachShah:patch-robotics-trace-narrow
Open

narrow except Exception in clothoid path planner and state machine display to specific types#1387
HrachShah wants to merge 2 commits into
AtsushiSakai:masterfrom
HrachShah:patch-robotics-trace-narrow

Conversation

@HrachShah

Copy link
Copy Markdown

What

Two bare except Exception blocks in PathPlanning/ClothoidPath/clothoid_path_planner.py (generate_clothoid_path outer try) and MissionPlanning/StateMachine/state_machine.py (PlantUML image display) were narrowed to specific exception tuples.

  • generate_clothoid_path outer try → except (ValueError, TypeError).
  • state_machine.py PlantUML display → except (OSError, ValueError, TypeError).

Why

generate_clothoid_path does numeric computations in solve_g_for_root and the compute_* helpers — these only raise ValueError (e.g. math.sin/math.cos of inf, numpy linalg convergence failures that propagate ValueError) and TypeError (when a parameter is the wrong shape, which should not be caught here either, but the original intent of the bare-except was clearly "skip and continue" for malformed geometry). Catching all Exception swallowed real bugs like NameError from a typo and AttributeError from a refactor.

state_machine.py PlantUML display opens a BytesIO buffer and calls plt.imshow(imread(BytesIO(content), format="png")). The realistic failure modes are OSError (matplotlib I/O failure, missing image format backend), ValueError (malformed image bytes), and TypeError (non-bytes content). KeyboardInterrupt and SystemExit should propagate during a long render.

Catching all Exception was the wrong shape for both blocks; narrowing preserves the original "skip and print a friendly message" intent while letting unrelated bugs surface.

Zo Bot added 2 commits May 25, 2026 03:40
…rom Exception to specific types — clothoid computations raise ValueError or TypeError; PlantUML image display raises OSError, ValueError, or TypeError; catching all Exception masked unrelated bugs
…o (ValueError, TypeError) — numeric computations in solve_g_for_root and compute_* helpers only raise these types; catching all Exception masked unrelated bugs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant