Skip to content

fix: resolve SonarQube issues in pokedex helper exception handling#3

Open
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260525-010119-adbf3513
Open

fix: resolve SonarQube issues in pokedex helper exception handling#3
sonarqube-agent[bot] wants to merge 1 commit into
mainfrom
remediate-main-20260525-010119-adbf3513

Conversation

@sonarqube-agent
Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Fixed 4 SonarQube code quality issues in pokedex/helper.py: removed generic exception raising and dead code from exception handlers, added missing raise keyword for ValueError, and eliminated redundant pass statement. These changes improve exception specificity, code clarity, and prevent unreachable code paths.

View Project in SonarCloud


Fixed Issues

python:S112 - Replace this generic exception class with a more specific one. • MAJORView issue

Location: pokedex/helper.py:20

Why is this an issue?

Raising instances of Exception and BaseException will have a negative impact on any code trying to catch these exceptions.

What changed

Removes the original except sqlite3.DatabaseError block that raised a generic Exception (a code smell because generic exceptions should not be raised) and that also caused the subsequent except sqlite3.IntegrityError clause to be dead code, since IntegrityError is a subclass of DatabaseError and would never be reached after the DatabaseError handler.

--- a/pokedex/helper.py
+++ b/pokedex/helper.py
@@ -19,2 +18,0 @@ class ConnectionWrapper:
-        except sqlite3.DatabaseError:
-            raise Exception("Problem with the database!")
python:S1045 - Catch this exception only once; it is already handled by a previous except clause. • MAJORView issue

Location: pokedex/helper.py:21

Why is this an issue?

Exceptions handlers (except) are evaluated in the order they are written. Once a match is found, the evaluation stops.

What changed

Removes the original except sqlite3.DatabaseError block that raised a generic Exception (a code smell because generic exceptions should not be raised) and that also caused the subsequent except sqlite3.IntegrityError clause to be dead code, since IntegrityError is a subclass of DatabaseError and would never be reached after the DatabaseError handler.

--- a/pokedex/helper.py
+++ b/pokedex/helper.py
@@ -19,2 +18,0 @@ class ConnectionWrapper:
-        except sqlite3.DatabaseError:
-            raise Exception("Problem with the database!")
python:S3984 - Raise this exception or remove this useless statement. • MAJORView issue

Location: pokedex/helper.py:36

Why is this an issue?

Creating a new Exception without actually raising it has no effect and is probably due to a mistake.

What changed

Adds the missing raise keyword before ValueError("Invalid email!"). Without raise, the exception was being created but never raised, making the statement a no-op. Now the exception is properly raised when an invalid email is encountered.

--- a/pokedex/helper.py
+++ b/pokedex/helper.py
@@ -36,1 +36,1 @@ def register_subscriber(wrapper: ConnectionWrapper, email):
-        ValueError("Invalid email!")
+        raise ValueError("Invalid email!")
python:S2772 - Remove this unneeded "pass". • MINORView issue

Location: pokedex/helper.py:38

Why is this an issue?

The use of a pass statement where it is not required by the syntax is redundant. It makes the code less readable and its intent confusing.

What changed

Removes the redundant pass statement that served no purpose since there was already other code in the block. This eliminates the code smell of having an unnecessary pass that reduces readability.

--- a/pokedex/helper.py
+++ b/pokedex/helper.py
@@ -38,1 +37,0 @@ def register_subscriber(wrapper: ConnectionWrapper, email):
-    pass

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZWCTWBhfksiPFt2jGS_ for python:S112 rule
- AZWCTWBhfksiPFt2jGS- for python:S1045 rule
- AZWCTWBhfksiPFt2jGTC for python:S3984 rule
- AZWCTWBhfksiPFt2jGTA for python:S2772 rule

Generated by SonarQube Agent (task: d81195d0-e5a4-4ebd-927f-993618debd9e)
@sonarqubecloud
Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant