Skip to content

fix(errors): standardize error handling with custom exception classes#1

Open
twenty-tools wants to merge 2 commits intomainfrom
fix/issue-10-error-handling
Open

fix(errors): standardize error handling with custom exception classes#1
twenty-tools wants to merge 2 commits intomainfrom
fix/issue-10-error-handling

Conversation

@twenty-tools
Copy link

@twenty-tools twenty-tools commented Mar 10, 2026

Fixes lighthouse-web3#10

Summary

Adds custom exception classes to standardize API and upload error handling, removing generic exception wrapping in the core paths touched by this issue.

Changes

  • Added src/lighthouseweb3/functions/exceptions.py with LighthouseError, LighthouseAPIError, and LighthouseUploadError.
  • Updated deal_status.py to raise LighthouseAPIError instead of generic exceptions.
  • Updated axios.py to raise LighthouseAPIError on HTTP failures.
  • Updated upload.py to raise LighthouseUploadError and avoid debug print noise.

Scope note

This PR is intentionally scoped to issue lighthouse-web3#10 error handling. PR lighthouse-web3#11 addresses broader concerns like type hints, docstrings, and resource management.

Validation

  • python -m unittest discover tests/

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

4 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lighthouseweb3/functions/upload.py">

<violation number="1" location="src/lighthouseweb3/functions/upload.py:56">
P2: Catching `Exception` here re-wraps `LighthouseAPIError` (already raised by `Axios` methods) into a `LighthouseUploadError`, erasing the original exception type. Let `LighthouseError` subclasses propagate and only wrap unexpected errors.</violation>
</file>

<file name="src/lighthouseweb3/functions/deal_status.py">

<violation number="1" location="src/lighthouseweb3/functions/deal_status.py:13">
P2: Use `raise LighthouseAPIError(...) from error` to explicitly chain the original `HTTPError`. Without `from`, the cause is only implicitly attached, producing a less clear traceback and making it easy for callers to miss the original status code and URL context.</violation>
</file>

<file name="src/lighthouseweb3/functions/axios.py">

<violation number="1" location="src/lighthouseweb3/functions/axios.py:21">
P2: The try body only does string concatenation, which cannot raise `LighthouseAPIError` or `HTTPError`. This except clause is unreachable. Either remove the try/except entirely or catch the exceptions that dict iteration/string formatting can actually raise (e.g., `TypeError`).</violation>

<violation number="2" location="src/lighthouseweb3/functions/axios.py:30">
P1: Same resource-leak issue as `post_files`: non-`HTTPError` request failures (e.g. `ConnectionError`) skip the except block, so `file.close()` never runs. Widen the catch to `RequestException` or move cleanup to a `finally`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@twenty-tools
Copy link
Author

@laciferin2024

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.

Inconsistent Error Handling Needs Standardization

2 participants