Skip to content

Commit

Permalink
try/catch mutant generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bohendo committed Jan 27, 2025
1 parent e8d6903 commit ade58c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 8 additions & 3 deletions slither/tools/mutator/mutators/abstract_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from slither.formatters.utils.patches import apply_patch, create_diff
from slither.tools.mutator.utils.testing_generated_mutant import test_patch
from slither.core.declarations import Contract
from slither.utils.colors import red

logger = logging.getLogger("Slither-Mutate")

Expand Down Expand Up @@ -70,13 +71,17 @@ def __init__( # pylint: disable=too-many-arguments

@abc.abstractmethod
def _mutate(self) -> Dict:
"""TODO Documentation"""
"""Abstract placeholder, will be overwritten by each mutator"""
return {}

# pylint: disable=too-many-branches
def mutate(self) -> Tuple[List[int], List[int], List[int]]:
# call _mutate function from different mutators
(all_patches) = self._mutate()
all_patches: Dict = {}
try:
# call _mutate function from different mutators
(all_patches) = self._mutate()
except Exception as e:

Check warning on line 83 in slither/tools/mutator/mutators/abstract_mutator.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

W0718: Catching too general exception Exception (broad-exception-caught)
logger.error(red("%s mutator failed in %s: %s"), self.NAME, self.contract.name, str(e))
if "patches" not in all_patches:
logger.debug("No patches found by %s", self.NAME)
return [0, 0, 0], [0, 0, 0], self.dont_mutate_line
Expand Down
4 changes: 1 addition & 3 deletions slither/tools/mutator/utils/testing_generated_mutant.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def test_patch( # pylint: disable=too-many-arguments

create_mutant_file(output_folder, file, generator_name)
logger.info(
red(
f"[{generator_name}] Line {patch['line_number']}: '{patch['old_string']}' ==> '{patch['new_string']}' --> UNCAUGHT"
)
f"[{generator_name}] Line {patch['line_number']}: '{patch['old_string']}' ==> '{patch['new_string']}' --> UNCAUGHT"
)
reset_file(file)

Expand Down

0 comments on commit ade58c3

Please sign in to comment.