Skip to content

Guard log stream setup against missing TOC variables#813

Open
evanofficial wants to merge 1 commit into
bitcraze:cflib2from
evanofficial:guard-log-streams-against-missing-toc-vars
Open

Guard log stream setup against missing TOC variables#813
evanofficial wants to merge 1 commit into
bitcraze:cflib2from
evanofficial:guard-log-streams-against-missing-toc-vars

Conversation

@evanofficial
Copy link
Copy Markdown

Fixes #800.

Wraps the three async block.add_variable() setup sites flagged in the issue with log.names() presence checks, mirroring the existing supervisor.info guard in _stream_motors. When a variable is missing from the firmware log TOC, it is skipped with a warning rather than raising inside the create_task() coroutine.

Per-file changes

  • src/cfclient/ui/tabs/FlightTab.py (_stream_motors) — guards stabilizer.thrust, motor.m1m4, sys.canfly, and supervisor.info (existing guard folded into the new loop). _log_data_received now checks key presence before reading each motor / thrust / can-fly value, matching the pattern already used for supervisor.info.
  • src/cfclient/ui/main.py (_stream_battery) — guards pm.vbat and pm.state. The stream loop only emits _battery_signal when both keys are present in the sample.
  • src/cfclient/ui/pose_logger.py (_stream_loop) — guards all six stateEstimate.* variables. The consumer uses data.data.get(name, 0.0) so missing axes fall back to the existing NO_POSE default value rather than raising.

Notes on scope

The issue lists three specific async setup sites; this PR only touches those. There are other add_variable() callers in the codebase that use the older synchronous log-config API (e.g. GpsTab.py, ColorLEDTab.py, lighthouse_tab.py, locopositioning_tab.py, cfzmq/__init__.py) — different surface, different failure mode, left alone to keep the diff surgical. Happy to follow up in a separate PR if a similar guard is wanted there.

No new tests: there is no pytest harness wired into the cflib2 CI yet, and these UI-coupled async streams would need a non-trivial mock setup. The guards are conservative — they only short-circuit when a name is absent from log.names(), otherwise behavior is unchanged.

Wrap async block.add_variable() calls in _stream_motors (FlightTab),
_stream_battery (MainUI), and _stream_loop (PoseLogger) with log.names()
presence checks, mirroring the existing supervisor.info guard. When a
variable is absent from the firmware's log TOC, it is skipped with a
warning instead of raising inside the create_task() coroutine.

Consumers are updated to tolerate missing keys so the streams continue
to deliver any available data without crashing the tab or silently
killing the streaming task.
@gemenerik gemenerik requested a review from ataffanel May 22, 2026 07:37
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