Skip to content

Refactor logging to use debug for error related API calls#251

Merged
soimkim merged 1 commit intomainfrom
logging
Mar 3, 2026
Merged

Refactor logging to use debug for error related API calls#251
soimkim merged 1 commit intomainfrom
logging

Conversation

@soimkim
Copy link
Contributor

@soimkim soimkim commented Mar 3, 2026

Description

Refactor logging to use debug for error related API calls.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation update
  • Refactoring, Maintenance
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

@soimkim soimkim self-assigned this Mar 3, 2026
@soimkim soimkim added the chore [PR/Issue] Refactoring, maintenance the code label Mar 3, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Logging level changes in exception handlers throughout the _scan_item.py file. Several exception handlers that previously emitted warning logs have been updated to emit debug logs instead, without altering control flow or return-value behavior.

Changes

Cohort / File(s) Summary
Logging Level Adjustments
src/fosslight_source/_scan_item.py
Exception handlers in _get_hash and _get_origin_url_from_md5_hash methods changed from warning to debug logging level (FileNotFoundError, PermissionError, URLError, json.JSONDecodeError, and general exceptions).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 clearly summarizes the main change: refactoring logging levels from warnings to debug for exception handlers in API-related functions.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch logging

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

@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_source/_scan_item.py (1)

102-103: Narrow blind Exception catches to expected types.

Line 102 and Line 128 still catch Exception. However, the suggested refactors require adjustments:

Line 102–103: Refactoring to only OSError may be too narrow. The try block includes an external library call (Winnowing().wfp_for_file()), which could raise exceptions outside the OSError hierarchy. Consider whether you need to keep the broad Exception catch for that external dependency, or document the specific exceptions expected.

Line 128–129: The suggestion is incomplete. The urlopen(request, timeout=10) call can raise socket.timeout (which is TimeoutError, a subclass of OSError), which is not caught by the existing urllib.error.URLError handler. The refactored exception tuple should include TimeoutError in addition to UnicodeDecodeError, TypeError, and ValueError:

Suggested refactor
-        except Exception as e:
+        except (UnicodeDecodeError, TypeError, ValueError, TimeoutError) as e:
             logger.debug(f"Error getting origin_url for MD5 hash {md5_hash}: {e}")

For line 102–103, reconsider whether the catch should remain broad to handle external library exceptions, or narrow with additional documentation.

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

In `@src/fosslight_source/_scan_item.py` around lines 102 - 103, The catch around
computing MD5 (the try calling Winnowing().wfp_for_file()/compute MD5 for
self.source_name_or_path) should avoid a blind Exception: either narrow it to
the concrete exceptions the Winnowing call can raise (document and list them) or
keep a broad catch but log the full traceback (logger.exception) so external-lib
errors are visible; update the except block for the MD5 compute accordingly
referencing Winnowing().wfp_for_file and the MD5 compute code. For the URL read
block that calls urlopen(request, timeout=10), expand the except tuple to
include TimeoutError in addition to UnicodeDecodeError, TypeError and ValueError
(and keep urllib.error.URLError handling separate) so socket timeouts are
caught; update the except clause that references urlopen(request, timeout=10) to
(UnicodeDecodeError, TypeError, ValueError, TimeoutError) and ensure logging
remains informative.
🤖 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_source/_scan_item.py`:
- Around line 102-103: The catch around computing MD5 (the try calling
Winnowing().wfp_for_file()/compute MD5 for self.source_name_or_path) should
avoid a blind Exception: either narrow it to the concrete exceptions the
Winnowing call can raise (document and list them) or keep a broad catch but log
the full traceback (logger.exception) so external-lib errors are visible; update
the except block for the MD5 compute accordingly referencing
Winnowing().wfp_for_file and the MD5 compute code. For the URL read block that
calls urlopen(request, timeout=10), expand the except tuple to include
TimeoutError in addition to UnicodeDecodeError, TypeError and ValueError (and
keep urllib.error.URLError handling separate) so socket timeouts are caught;
update the except clause that references urlopen(request, timeout=10) to
(UnicodeDecodeError, TypeError, ValueError, TimeoutError) and ensure logging
remains informative.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 689eb2b and 57982b7.

📒 Files selected for processing (1)
  • src/fosslight_source/_scan_item.py

@soimkim soimkim merged commit fd42e3b into main Mar 3, 2026
6 of 7 checks passed
@soimkim soimkim deleted the logging branch March 3, 2026 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore [PR/Issue] Refactoring, maintenance the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant