Skip to content

Gracefully handle SCANOSS errors and hide KB completed message#299

Merged
soimkim merged 4 commits into
mainfrom
fix/scanoss-rate-limit-timeout
Jul 19, 2026
Merged

Gracefully handle SCANOSS errors and hide KB completed message#299
soimkim merged 4 commits into
mainfrom
fix/scanoss-rate-limit-timeout

Conversation

@JustinWonjaePark

@JustinWonjaePark JustinWonjaePark commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Key Changes

  • Pre-check SCANOSS API connectivity: Send a lightweight dummy WFP POST request before starting the full scan to detect API rate limits (HTTP 429/503) or connectivity issues early, avoiding unnecessary fingerprint generation.
  • Disable SCANOSS SDK retries: Set retry=0 to prevent unnecessary wait times from internal retries.
  • Enhance exception handling: Isolated scanning and parsing into separate try-except blocks to gracefully log errors/warnings without interrupting the overall execution flow.
  • Expand failure detection patterns: Added more patterns to detect API rate limits (HTTP 429) and timeouts/unavailability issues (e.g., HTTP 503, ConnectionError).
  • Fix CLI test: Adjusted the signature of run_scanoss_py in tests/cli_test.py.
  • Hide KB completed message from Cover sheet: Prevent writing KB(...) : Completed to the Cover sheet comments when KB scan completes successfully, while keeping other failure status messages.

Signed-off-by: Park Wonjae <wonjae.park@lge.com>
@JustinWonjaePark JustinWonjaePark self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

SCANOSS and report updates

Layer / File(s) Summary
SCANOSS runner setup
src/fosslight_source/run_scanoss.py, build/lib/fosslight_source/run_scanoss.py
Initializes captured output, configures the scanner, checks API readiness, and exposes ScanOSS result metadata parsing.
SCANOSS connectivity and failure detection
src/fosslight_source/run_scanoss.py, build/lib/fosslight_source/run_scanoss.py
Detects authentication, readiness, timeout, rate-limit, error, and rejected-output conditions and sets the skipped flag.
Result processing and report status
src/fosslight_source/run_scanoss.py, build/lib/fosslight_source/run_scanoss.py, src/fosslight_source/cli.py, tests/cli_test.py
Filters and parses ScanOSS JSON results, handles parse failures, cleans generated files, preserves KB cover comments, and updates the CLI test call to use keyword arguments.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant run_scanoss_py
  participant Scanner
  participant SCANOSS_API
  participant Report
  CLI->>run_scanoss_py: invoke with named scan options
  run_scanoss_py->>SCANOSS_API: send dummy WFP connectivity check
  SCANOSS_API-->>run_scanoss_py: return API status
  run_scanoss_py->>Scanner: execute scan with captured output
  Scanner-->>run_scanoss_py: return output or failure indicators
  run_scanoss_py->>Report: return parsed results and skipped flag
  Report-->>CLI: preserve KB cover-comment status
Loading

Possibly related PRs

Suggested reviewers: soimkim

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main SCANOSS error handling and KB completed-message behavior changes.
✨ 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 fix/scanoss-rate-limit-timeout

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.

Signed-off-by: Park Wonjae <wonjae.park@lge.com>
Signed-off-by: Park Wonjae <wonjae.park@lge.com>
@JustinWonjaePark
JustinWonjaePark force-pushed the fix/scanoss-rate-limit-timeout branch from cdac8c1 to b25c578 Compare July 16, 2026 04:00
@JustinWonjaePark JustinWonjaePark changed the title fix: gracefully handle SCANOSS API rate limits and timeouts fix: gracefully handle SCANOSS errors and hide KB completed message Jul 16, 2026
@JustinWonjaePark
JustinWonjaePark requested a review from soimkim July 16, 2026 04:37
@JustinWonjaePark
JustinWonjaePark marked this pull request as ready for review July 16, 2026 04:37

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/cli_test.py (1)

29-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefix the unused variable api_limit_exceed with an underscore.

The api_limit_exceed variable unpacked from run_scanoss_py is not used within the test. Prefixing it with an underscore signals that this is intentional and resolves the static analysis warning.

♻️ Proposed fix
-    ret_scanoss, api_limit_exceed = run_scanoss_py(
+    ret_scanoss, _api_limit_exceed = run_scanoss_py(
         path_to_find_bin,
         output_path=fosslight_report_name,
         format=[],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/cli_test.py` around lines 29 - 36, Rename the unused second
return-value variable in the run_scanoss_py call within the test to
_api_limit_exceed, preserving the existing unpacking and behavior while
resolving the static-analysis warning.

Source: Linters/SAST tools

src/fosslight_source/run_scanoss.py (1)

62-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Close the StringIO buffer to free up memory.

Although io.StringIO buffers are memory-backed and will eventually be garbage collected, it is a good practice to explicitly close them when they are no longer needed.

♻️ Proposed fix

Apply the following change after you have extracted the buffer's value at line 81:

     captured_output = output_buffer.getvalue()
+    output_buffer.close()
     if captured_output:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fosslight_source/run_scanoss.py` at line 62, Close the output_buffer
StringIO after extracting its value in run_scanoss, ensuring all reads from the
buffer occur before closing it and preserving the existing output behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fosslight_source/run_scanoss.py`:
- Around line 78-81: Update the exception handling around
Scanner.scan_folder_with_options() to retain the exception message in the output
used by subsequent API-limit and timeout pattern matching. Append or otherwise
check the caught error alongside output_buffer content before the existing
detection logic runs, while preserving the current debug logging.

---

Nitpick comments:
In `@src/fosslight_source/run_scanoss.py`:
- Line 62: Close the output_buffer StringIO after extracting its value in
run_scanoss, ensuring all reads from the buffer occur before closing it and
preserving the existing output behavior.

In `@tests/cli_test.py`:
- Around line 29-36: Rename the unused second return-value variable in the
run_scanoss_py call within the test to _api_limit_exceed, preserving the
existing unpacking and behavior while resolving the static-analysis warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b85d8752-1425-447c-a4ad-7e058484f796

📥 Commits

Reviewing files that changed from the base of the PR and between 2267c2a and b25c578.

📒 Files selected for processing (3)
  • src/fosslight_source/cli.py
  • src/fosslight_source/run_scanoss.py
  • tests/cli_test.py

Comment thread src/fosslight_source/run_scanoss.py

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fosslight_source/run_scanoss.py`:
- Around line 81-86: Use the caller-provided timeout in the preflight
session.post call within run_scanoss_py instead of the hardcoded five-second
value, and keep the generated copy synchronized by applying the same change in
src/fosslight_source/run_scanoss.py lines 81-86 and
build/lib/fosslight_source/run_scanoss.py lines 81-86.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1ac285cd-f7f0-4b99-bb7e-4bd978de6d13

📥 Commits

Reviewing files that changed from the base of the PR and between b25c578 and e4773e0.

📒 Files selected for processing (2)
  • build/lib/fosslight_source/run_scanoss.py
  • src/fosslight_source/run_scanoss.py

Comment thread src/fosslight_source/run_scanoss.py
Check API availability and rate limit status by sending a
dummy WFP POST request before starting the full scan.
This avoids wasting time generating fingerprints when the
SCANOSS API is unreachable or rate-limited.

Signed-off-by: Park Wonjae <wonjae.park@lge.com>
@JustinWonjaePark
JustinWonjaePark marked this pull request as draft July 16, 2026 06:15
@JustinWonjaePark
JustinWonjaePark force-pushed the fix/scanoss-rate-limit-timeout branch from e4773e0 to 4051831 Compare July 16, 2026 06:16
@JustinWonjaePark
JustinWonjaePark marked this pull request as ready for review July 16, 2026 06:22
@soimkim soimkim changed the title fix: gracefully handle SCANOSS errors and hide KB completed message Gracefully handle SCANOSS errors and hide KB completed message Jul 16, 2026
@soimkim soimkim added the bug fix [PR] Fix the bug label Jul 16, 2026
if os.path.exists(output_json_file):
os.remove(output_json_file)

output_buffer = io.StringIO()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@JustinWonjaePark , 추후 output_buffer.close() 권장드립니다.

@soimkim
soimkim merged commit b8a661f into main Jul 19, 2026
8 checks passed
@soimkim
soimkim deleted the fix/scanoss-rate-limit-timeout branch July 19, 2026 21:33
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