Skip to content

fix: replace bare except with except Exception (PEP 8 E722)#2049

Open
harshadkhetpal wants to merge 3 commits intorobusta-dev:masterfrom
harshadkhetpal:fix/bare-except-to-exception
Open

fix: replace bare except with except Exception (PEP 8 E722)#2049
harshadkhetpal wants to merge 3 commits intorobusta-dev:masterfrom
harshadkhetpal:fix/bare-except-to-exception

Conversation

@harshadkhetpal
Copy link
Copy Markdown

Summary

Replace bare except: clauses with except Exception: in three files:

  • src/robusta/core/sinks/transformer.py
  • src/robusta/integrations/prometheus/models.py
  • src/robusta/core/sinks/robusta/prometheus_discovery_utils.py

Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit, which can mask critical errors and make debugging harder. Using except Exception: is the PEP 8 recommended practice (E722) and preserves the ability to interrupt the program.

Change:

# Before
except:
    ...

# After
except Exception:
    ...

Testing

No behavior change for normal exception handling — this is a correctness/style fix that only affects the handling of BaseException subclasses like KeyboardInterrupt.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7aeb74d7-9409-44da-8bcb-743a547aa1dc

📥 Commits

Reviewing files that changed from the base of the PR and between c147b7d and 276985b.

📒 Files selected for processing (3)
  • src/robusta/core/sinks/robusta/prometheus_discovery_utils.py
  • src/robusta/core/sinks/transformer.py
  • src/robusta/integrations/prometheus/models.py

Walkthrough

These changes narrow exception handlers in three utility methods from catching all thrown values to only catching Exception instances, allowing system-level errors and control-flow signals to propagate without being suppressed.

Changes

Cohort / File(s) Summary
Exception handler refinement
src/robusta/core/sinks/robusta/prometheus_discovery_utils.py, src/robusta/core/sinks/transformer.py, src/robusta/integrations/prometheus/models.py
Changed bare except: clauses to except Exception: in three utility methods, preventing non-Exception errors from being caught while preserving existing exception logging and control flow behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Title check ✅ Passed The title clearly and concisely summarizes the main change: replacing bare except clauses with except Exception following PEP 8 E722.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for replacing bare except with except Exception across three files.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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