Skip to content

Commit

Permalink
pylint: Fix places that raise an overly broad exception
Browse files Browse the repository at this point in the history
pylint 2.17.2 (Fedora 38) complains about places that raise an overly broad
exception, such as bare 'Exception' rather than a derived class.  Change
most places that do that to raise an appropriate derived class.  One
remaining place appears to be deliberately raising the generic exception,
so use a pylint suppression there instead.

Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Jun 22, 2023
1 parent 7d7832c commit 587a6f3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions avocado/utils/external/gdbmi_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
from avocado.utils.external import spark


class GdbMiException(Exception):
pass


class Token:
def __init__(self, token_type, value=None):
self.type = token_type
Expand Down Expand Up @@ -126,7 +130,7 @@ def t_c_string(self, s):

def t_default(self, s): # pylint: disable=W0221
r"( . | \n )+"
raise Exception(f"Specification error: unmatched input for '{s}'")
raise GdbMiException(f"Specification error: unmatched input for '{s}'")

@staticmethod
def __unescape(s):
Expand Down Expand Up @@ -200,7 +204,7 @@ def nonterminal(self, token_type, args):
def error(self, token, i=0, tokens=None): # pylint: disable=W0221
if i > 2:
print(f"{tokens[i - 3]} {tokens[i - 2]} " f"{tokens[i - 1]} {tokens[i]}")
raise Exception(f"Syntax error at or near {int(i)}:'{token}' token")
raise GdbMiException(f"Syntax error at or near {int(i)}:'{token}' token")


class GdbMiInterpreter(spark.GenericASTTraversal):
Expand Down Expand Up @@ -249,7 +253,7 @@ def n_tuple(node):
else:
node.value[n] = v
else:
raise Exception("Invalid tuple")
raise GdbMiException("Invalid tuple")
# print 'tuple: %s' % node.value

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion avocado/utils/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ def cmd(self, command):
if result_response_received:
# raise an exception here, because no two result
# responses should come from a single command AFAIK
raise Exception("Many result responses to a single cmd")
raise UnexpectedResponseError(
"Many result responses to a single cmd"
)
result_response_received = True
cmd.result = parsed_response
else:
Expand Down
2 changes: 1 addition & 1 deletion avocado/utils/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def uncompress(self):
LOG.info("Uncompressing tarball")
archive.extract(self.asset_path, self.work_dir)
else:
raise Exception("Unable to find the tarball")
raise RuntimeError("Unable to find the tarball")

def configure(self, targets=("defconfig"), extra_configs=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/multiple_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def action():
"""
This method should never execute
"""
raise Exception("This action method should never be executed.")
raise RuntimeError("This action method should never be executed.")
2 changes: 1 addition & 1 deletion examples/tests/uncaught_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def test():
"""
This should end with ERROR.
"""
raise Exception("This is a generic exception")
raise Exception("This is a generic exception") # pylint: disable=W0719

0 comments on commit 587a6f3

Please sign in to comment.