Guard log stream setup against missing TOC variables#813
Open
evanofficial wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #800.
Wraps the three async
block.add_variable()setup sites flagged in the issue withlog.names()presence checks, mirroring the existingsupervisor.infoguard in_stream_motors. When a variable is missing from the firmware log TOC, it is skipped with a warning rather than raising inside thecreate_task()coroutine.Per-file changes
src/cfclient/ui/tabs/FlightTab.py(_stream_motors) — guardsstabilizer.thrust,motor.m1–m4,sys.canfly, andsupervisor.info(existing guard folded into the new loop)._log_data_receivednow checks key presence before reading each motor / thrust / can-fly value, matching the pattern already used forsupervisor.info.src/cfclient/ui/main.py(_stream_battery) — guardspm.vbatandpm.state. The stream loop only emits_battery_signalwhen both keys are present in the sample.src/cfclient/ui/pose_logger.py(_stream_loop) — guards all sixstateEstimate.*variables. The consumer usesdata.data.get(name, 0.0)so missing axes fall back to the existingNO_POSEdefault 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.