fix: handle Nirjas extraction errors and optimize file fallback #114#120
Open
Abh-igyan wants to merge 2 commits intofossology:masterfrom
Open
fix: handle Nirjas extraction errors and optimize file fallback #114#120Abh-igyan wants to merge 2 commits intofossology:masterfrom
Abh-igyan wants to merge 2 commits intofossology:masterfrom
Conversation
- Wrap commentExtract() call in try/except to prevent scan crashes when Nirjas fails to parse supported file types (fixes fossology#114) - Replace inefficient read().split() pattern with shutil.copyfileobj() in both the exception fallback and unsupported file type paths - Add logging.warning() to surface extraction failures without terminating the scan"
hastagAB
approved these changes
Mar 25, 2026
Member
hastagAB
left a comment
There was a problem hiding this comment.
Hey @Abh-igyan, The fix LGTM!
As a follow-up, it'd be nice to: Narrow the except Exception to IndexError
But nothing blocking here. Thanks for the contribution! 🎉
Author
|
"Thanks for the review @hastagAB ! Updated the except clause to catch IndexError specifically as suggested." Will try to think about those intricacies from now. |
Author
|
Hey @hastagAB <https://github.com/hastagAB> @Kaushl2208
<https://github.com/Kaushl2208> @shaheemazmalmmd
<https://github.com/shaheemazmalmmd> @its-sushant
<https://github.com/its-sushant> @GMishx <https://github.com/GMishx>*.
*I've updated
the except clause as suggested. Also ran Atarashi on BusyBox to verify the
fix — scan completes without crashing now
[image: resolved.png]
While working on understanding the Nirjas-Atarashi pipeline for this fix, I
also built a small POC exploring ML-based comment classification as part of
my GSoC proposal: https://github.com/Abh-igyan/Nirjas-ML-POC (already
shared on discussions page few days ago but received no feedback)
Would really appreciate a quick look at the proposal draft
<https://docs.google.com/document/d/1T2PqpRmekFOdYjxPqc1NnAv46URyeatT/edit?usp=sharing&ouid=109378995334582097647&rtpof=true&sd=true>
if you have a moment before the deadline. Happy to share it here.
…On Wed, 25 Mar 2026 at 16:06, Ayush Bhardwaj ***@***.***> wrote:
***@***.**** approved this pull request.
Hey @Abh-igyan <https://github.com/Abh-igyan>, The fix LGTM!
As a follow-up, it'd be nice to: Narrow the except Exception to IndexError
But nothing blocking here. Thanks for the contribution! 🎉
—
Reply to this email directly, view it on GitHub
<#120?email_source=notifications&email_token=BNWHLCFGUQTVVWH4IMX2FPT4SOZDLA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBQGU3DGNZWHA42M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#pullrequestreview-4005637689>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BNWHLCHAQY7RPLOUTTQ6WQT4SOZDLAVCNFSM6AAAAACW4EL7DWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DAMBVGYZTONRYHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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.
Description
Fixes a crash in the TF-IDF agent caused by unhandled exceptions during Nirjas comment extraction, and optimizes the file fallback mechanism by replacing inefficient in-memory reads with shutil.copyfileobj().
Changes
Wrapped commentExtract() call in a try/except block inside CommentPreprocessor.extract() to gracefully handle Nirjas parsing failures instead of crashing the entire scan
Replaced inFile.read().split('\n') pattern with shutil.copyfileobj() in the exception fallback path — avoids loading the entire file into memory
Applied the same shutil.copyfileobj() optimization to the unsupported file extension fallback (else block) which had the same inefficiency
Added logging.warning() to surface extraction failures without terminating the scan
Added shutil and logging to imports
shutil uses chunk based writing thus reducing RAM overload. Impressive right?
How to test
Clone the repository and install dependencies:
(remember to install poetry with curl and not apt (gives old version).
Use this:
curl -sSL https://install.python-poetry.org | python3 -bash
Download BusyBox (the real-world project that triggers the crash):
bash
Run the TF-IDF agent scan on the extracted source tree:
bash
poetry run atarashi -a tfidf -s CosineSim ./busybox-1.36.1#use poetry run and not just atarashi; atarashi is not installed in your global system path; it lives inside the Poetry virtual environment we just built.
Inferences:
The scan completes without raising IndexError: list index out of range
A WARNING log appears for any file Nirjas fails to parse
The scan continues and produces results for remaining files
Fixes #114