Skip to content

fix: remove return statements from finally blocks#10102

Merged
jfagoagas merged 4 commits intoprowler-cloud:masterfrom
apoorvdarshan:fix/remove-return-in-finally-blocks
Mar 27, 2026
Merged

fix: remove return statements from finally blocks#10102
jfagoagas merged 4 commits intoprowler-cloud:masterfrom
apoorvdarshan:fix/remove-return-in-finally-blocks

Conversation

@apoorvdarshan
Copy link
Copy Markdown
Contributor

Summary

  • Removed all 16 return statements from finally blocks across 5 files to prevent silent exception swallowing
  • Moved return variable initialization before try blocks and replaced finally: return with plain return after try/except
  • Preserves existing behavior (returning default values on error) while allowing unexpected exceptions to propagate correctly

Files Changed

File Instances Fixed
prowler/providers/aws/services/iam/iam_service.py 11
prowler/providers/aws/services/organizations/organizations_service.py 2
prowler/lib/check/custom_checks_metadata.py 1
prowler/providers/aws/services/iam/iam_user_two_active_access_key/iam_user_two_active_access_key.py 1
prowler/providers/gcp/gcp_provider.py 1

Context

A return in a finally block silently suppresses any in-flight exception, including BaseException types like KeyboardInterrupt. See Python docs.

Fixes #5520

Test plan

  • Verify existing unit tests pass with no regressions
  • Confirm error handling behavior is preserved (default values returned on caught exceptions)

…ng exceptions

A return statement in a finally block silently suppresses any in-flight
exception, including BaseException types like KeyboardInterrupt. This
makes debugging difficult and can mask real errors.

Move return variable initialization before the try block and replace
finally: return with a plain return after the try/except. This preserves
the existing behavior (returning default values on error) while allowing
unexpected exceptions to propagate correctly.

Fixes prowler-cloud#5520
@apoorvdarshan apoorvdarshan requested review from a team as code owners February 17, 2026 20:37
@github-actions github-actions bot added provider/aws Issues/PRs related with the AWS provider provider/gcp Issues/PRs related with the Google Cloud Platform provider community Opened by the Community labels Feb 17, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 17, 2026

Conflict Markers Resolved

All conflict markers have been successfully resolved in this pull request.

josema-xyz
josema-xyz previously approved these changes Feb 18, 2026
Copy link
Copy Markdown
Contributor

@josema-xyz josema-xyz left a comment

Choose a reason for hiding this comment

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

Nice job! 🚀

@jfagoagas jfagoagas requested a review from josema-xyz March 27, 2026 07:52
else:
try:
setattr(check_metadata, attribute, custom_metadata[attribute])
except ValueError:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.13%. Comparing base (041f95b) to head (c6cd862).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10102      +/-   ##
==========================================
+ Coverage   26.36%   36.13%   +9.76%     
==========================================
  Files         839     1072     +233     
  Lines       23898    33936   +10038     
==========================================
+ Hits         6301    12262    +5961     
- Misses      17597    21674    +4077     
Flag Coverage Δ
prowler-py3.10-aws 19.77% <100.00%> (-6.47%) ⬇️
prowler-py3.10-gcp 28.92% <92.85%> (?)
prowler-py3.10-lib 36.12% <94.73%> (?)
prowler-py3.11-aws 19.77% <100.00%> (-6.54%) ⬇️
prowler-py3.11-gcp 28.92% <92.85%> (?)
prowler-py3.11-lib 36.11% <94.73%> (?)
prowler-py3.12-aws 19.78% <100.00%> (-6.54%) ⬇️
prowler-py3.12-gcp 28.93% <92.85%> (?)
prowler-py3.12-lib 36.12% <94.73%> (?)
prowler-py3.9-aws 19.79% <100.00%> (-6.47%) ⬇️
prowler-py3.9-gcp 28.94% <92.85%> (?)
prowler-py3.9-lib 36.13% <94.73%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
prowler 36.13% <94.73%> (+9.76%) ⬆️
api ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jfagoagas jfagoagas merged commit 7b0ce78 into prowler-cloud:master Mar 27, 2026
36 checks passed
@jfagoagas
Copy link
Copy Markdown
Member

Thanks for this @apoorvdarshan 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Opened by the Community provider/aws Issues/PRs related with the AWS provider provider/gcp Issues/PRs related with the Google Cloud Platform provider status/waiting-for-revision Waiting for maintainer's revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

return in finally can swallow exceptions

5 participants