Skip to content

fix: replace raise e with bare raise and improve error propagation in getBatchDetailsIter#134

Open
Adichapati wants to merge 1 commit into
ipinfo:masterfrom
Adichapati:wilson/20250624-fix-bare-raise-traceback
Open

fix: replace raise e with bare raise and improve error propagation in getBatchDetailsIter#134
Adichapati wants to merge 1 commit into
ipinfo:masterfrom
Adichapati:wilson/20250624-fix-bare-raise-traceback

Conversation

@Adichapati

Copy link
Copy Markdown

Summary

Fixes an exception chaining anti-pattern in Handler.getBatchDetailsIter that was masking original tracebacks.

Changes

  1. Replace raise e with bare raise (line 395)

    raise e creates a new exception without preserving the original traceback,
    making debugging significantly harder. Bare raise re-raises the active
    exception while keeping the full chain intact.

  2. Improve HTTP status handling

    • Capture status_code before the status-check try block so that the
      value is available if a JSON parse error occurs inside the block.
    • Added an explicit except RequestQuotaExceededError: raise clause so
      quota errors propagate naturally instead of being routed through the
      generic except Exception handler.
    • Added exception chaining (raise RequestQuotaExceededError() from e)
      for the unlikely case where a 429 arrives but is wrapped in a different
      exception type.
  3. Use is None instead of == None in getBatchDetails (line 235)

    PEP 8 style consistency -- the sibling method getBatchDetailsIter already
    used is None.

Impact

  • Tracebacks from network and HTTP errors are now fully actionable.
  • No behaviour change for successful requests or existing callers.

Verification

python3 -m py_compile ipinfo/handler.py   # passes

This is an AI-generated contribution. See bot-usage-policy.

- Use exception chaining (raise ... from e) to preserve traceback context
- Capture status_code before the body-parse error path
- Let RequestQuotaExceededError propagate naturally instead of
  collecting it into the catch-all handler

This makes tracebacks actionable (original exception chain is preserved)
and avoids masking quota errors as generic Exception.
Copilot AI review requested due to automatic review settings June 24, 2026 03:25

Copilot AI 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.

Pull request overview

Improves exception handling in Handler.getBatchDetailsIter to avoid masking original tracebacks, and aligns None comparisons with PEP 8 style in getBatchDetails.

Changes:

  • Replace raise e with bare raise when re-raising exceptions from requests.post.
  • Refactor HTTP status handling in getBatchDetailsIter (capture status_code, special-case 429 quota errors).
  • Use is None instead of == None for batch_size defaulting in getBatchDetails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ipinfo/handler.py
Comment on lines +403 to 408
except RequestQuotaExceededError:
raise
except Exception as e:
if status_code == 429 and not isinstance(e, RequestQuotaExceededError):
raise RequestQuotaExceededError() from e
return handler_utils.return_or_fail(raise_on_fail, e)
Comment thread ipinfo/handler.py
Comment on lines 392 to +395
try:
response = requests.post(url, json=batch, headers=headers)
except Exception as e:
raise e
except Exception:
raise
Comment thread ipinfo/handler.py
Comment on lines 399 to +404
try:
if response.status_code == 429:
if status_code == 429:
raise RequestQuotaExceededError()
response.raise_for_status()
except RequestQuotaExceededError:
raise
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.

2 participants