Skip to content

Commit

Permalink
Merge pull request #2417 from crytic/invalid-compilations-errors
Browse files Browse the repository at this point in the history
Reduce verbosity for InvalidCompilation errors
  • Loading branch information
0xalpharush authored Apr 24, 2024
2 parents 5636dff + dcec99b commit fb23f27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions slither/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing import Tuple, Optional, List, Dict, Type, Union, Any, Sequence


from crytic_compile import cryticparser, CryticCompile
from crytic_compile import cryticparser, CryticCompile, InvalidCompilation
from crytic_compile.platform.standard import generate_standard_export
from crytic_compile.platform.etherscan import SUPPORTED_NETWORK
from crytic_compile import compile_all, is_supported
Expand Down Expand Up @@ -93,7 +93,13 @@ def process_all(
detector_classes: List[Type[AbstractDetector]],
printer_classes: List[Type[AbstractPrinter]],
) -> Tuple[List[Slither], List[Dict], List[Output], int]:
compilations = compile_all(target, **vars(args))

try:
compilations = compile_all(target, **vars(args))
except InvalidCompilation:
logger.error("Unable to compile all targets.")
sys.exit(2)

slither_instances = []
results_detectors = []
results_printers = []
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys
import tempfile
import pytest

from slither.__main__ import main_impl


def test_cli_exit_on_invalid_compilation_file(caplog):

with tempfile.NamedTemporaryFile("w") as f:
f.write("pragma solidity ^0.10000.0;")

sys.argv = ["slither", f.name]
with pytest.raises(SystemExit) as pytest_wrapped_e:
main_impl([], [])

assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 2

assert caplog.record_tuples[0] == ("Slither", 40, "Unable to compile all targets.")

0 comments on commit fb23f27

Please sign in to comment.