Skip to content

fix: render gap.py invalid-AD debug log without raising TypeError#220

Merged
bdraco merged 1 commit into
mainfrom
koan/fix-gap-debug-log-format
May 15, 2026
Merged

fix: render gap.py invalid-AD debug log without raising TypeError#220
bdraco merged 1 commit into
mainfrom
koan/fix-gap-debug-log-format

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented May 15, 2026

Copy link
Copy Markdown
Contributor

What

Fix a stale format-string mismatch in the debug log emitted when _uncached_parse_advertisement_bytes rejects a malformed BLE GAP AD structure.

Why

The message string had three %s placeholders but the call only passed offset and gap_bytes. Any handler attached at DEBUG level for bluetooth_data_tools.gap raised:

TypeError: not enough arguments for format string

while rendering the record. The parser itself kept running (logging swallows the formatting error) but the stderr noise is misleading and the diagnostic message is unusable.

How

  • Pass length as the third argument and rename the placeholder to length=%s, which is the most actionable hint when the AD claims more bytes than remain in the buffer.
  • Add a regression test that triggers the branch with a fresh payload (so the lru_cache doesn't short-circuit) and renders every captured record — a future format-string mismatch will fail the test.

Testing

  • pytest tests/ --ignore=tests/benchmarks → 64 passed.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 15 insertions(+), 1 deletion(-)

Code scan: clean

Tests: failed ([Errno 13] Permission denied: 'pytest')

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The malformed-AD debug log used three %s placeholders but only passed
two arguments, so any DEBUG-level handler raised
"TypeError: not enough arguments for format string" while formatting
the record. Add the missing AD `length` argument so the message
renders cleanly and includes useful diagnostic context.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codspeed-hq

codspeed-hq Bot commented May 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing koan/fix-gap-debug-log-format (8ab8086) with main (c8bb40b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (493115d) during the generation of this report, so c8bb40b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c8bb40b) to head (8ab8086).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #220   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          248       248           
  Branches        37        37           
=========================================
  Hits           248       248           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a debug-log format string mismatch in the GAP advertisement parser so malformed AD structures can be logged at DEBUG level without raising a TypeError, and adds a regression test to ensure future log formatting errors are caught.

Changes:

  • Fix _LOGGER.debug(...) call in _uncached_parse_advertisement_bytes by passing the missing length argument and making the placeholder label explicit (length=%s).
  • Add a pytest regression test that triggers the invalid-AD branch and renders captured log records to ensure log formatting remains valid.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/bluetooth_data_tools/gap.py Fixes the debug log argument/placeholder mismatch by including length in the log call.
tests/test_gap.py Adds a regression test that exercises the malformed AD path and forces log message rendering to catch formatting errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bdraco bdraco marked this pull request as ready for review May 15, 2026 07:06
@bdraco bdraco merged commit c960e7c into main May 15, 2026
51 of 52 checks passed
@bdraco bdraco deleted the koan/fix-gap-debug-log-format branch May 15, 2026 07:06
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.

3 participants