Skip to content

Fix source files incorrectly included in binary results on Windows exe#200

Open
bjk7119 wants to merge 1 commit intomainfrom
remove
Open

Fix source files incorrectly included in binary results on Windows exe#200
bjk7119 wants to merge 1 commit intomainfrom
remove

Conversation

@bjk7119
Copy link
Copy Markdown
Contributor

@bjk7119 bjk7119 commented Apr 13, 2026

Description

  • Fix typo in keyword argument: modeerror_msg -> error_msg
  • Fix magic.from_buffer() to open files in binary mode ('rb') to avoid encoding errors and incorrect magic detection on Windows
  • Add python-magic and rfc3987_syntax data collection to PyInstaller hook to ensure magic database and .lark grammar file are bundled in the exe

Summary by CodeRabbit

  • Bug Fixes

    • Corrected binary file reading mode in file type detection
    • Enhanced error handling during binary analysis operations
  • Chores

    • Extended package resource collection for additional runtime dependencies

@bjk7119 bjk7119 requested review from dd-jy and soimkim April 13, 2026 04:59
@bjk7119 bjk7119 self-assigned this Apr 13, 2026
@bjk7119 bjk7119 added the bug fix [PR] Fix the bug label Apr 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

This PR extends the PyInstaller hook to collect resources from additional packages (magic and rfc3987_syntax) and fixes three minor issues in binary analysis: correcting an error handling parameter name, updating a debug log message, and ensuring file I/O operates in binary mode.

Changes

Cohort / File(s) Summary
PyInstaller Hook Extension
hooks/hook-fosslight_binary.py
Added resource collection calls for magic and rfc3987_syntax packages, appending their datas, binaries, and hiddenimports to the existing hook accumulators.
Binary Analysis Fixes
src/fosslight_binary/binary_analysis.py
Corrected error handling parameter name (modeerror_msgerror_msg), updated debug log message context (get_file_listcheck_binary), and changed file read mode to binary ('rb') when magic.from_file detection fails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Fix tox error #181 — Modifies the same PyInstaller hook to append package resources in a similar manner.

Suggested labels

chore

Suggested reviewers

  • dd-jy
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references fixing source files in binary results on Windows exe, which aligns with the PR's objectives of correcting magic detection and fixing issues on Windows by bundling magic database and grammar files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/fosslight_binary/binary_analysis.py (1)

313-316: Narrow the exception handler to catch specific expected exceptions.

On lines 313-316, except Exception can mask non-recoverable bugs. Since the try block performs file operations and binary checks, catch only the expected exceptions from these paths—such as FileNotFoundError, PermissionError, or OSError—instead of masking all exceptions. Currently, the handler still yields file_item despite the error, making failure look like success.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/fosslight_binary/binary_analysis.py` around lines 313 - 316, The broad
except in check_binary currently masks all errors and still yields file_item;
change it to catch only expected file-related exceptions (e.g.,
FileNotFoundError, PermissionError, OSError) in the except block that logs via
logger.debug and sets file_item.comment, and for any other unexpected Exception
re-raise after logging so real bugs aren’t hidden; ensure the yield file_item
remains only inside the narrow except branch that handles those expected
exceptions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/fosslight_binary/binary_analysis.py`:
- Around line 313-316: The broad except in check_binary currently masks all
errors and still yields file_item; change it to catch only expected file-related
exceptions (e.g., FileNotFoundError, PermissionError, OSError) in the except
block that logs via logger.debug and sets file_item.comment, and for any other
unexpected Exception re-raise after logging so real bugs aren’t hidden; ensure
the yield file_item remains only inside the narrow except branch that handles
those expected exceptions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48dfbb84-47e0-4a2a-9b0a-b3fa03c4a038

📥 Commits

Reviewing files that changed from the base of the PR and between ac49efd and 1a0fd53.

📒 Files selected for processing (2)
  • hooks/hook-fosslight_binary.py
  • src/fosslight_binary/binary_analysis.py

@dd-jy dd-jy changed the title fix(executable): fix source files incorrectly included in binary results on Windows exe ix source files incorrectly included in binary results on Windows exe Apr 13, 2026
@dd-jy dd-jy changed the title ix source files incorrectly included in binary results on Windows exe Fix source files incorrectly included in binary results on Windows exe Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix [PR] Fix the bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants