Add solc error handling

pull/22/head
Bernhard Mueller 7 years ago
parent 9ffaafa418
commit ce64d13e3f
  1. 9
      myth
  2. 10
      mythril/ether/util.py
  3. 2
      mythril/exceptions.py

@ -12,6 +12,7 @@ from mythril.ether.util import compile_solidity
from mythril.rpc.client import EthJsonRpc
from mythril.ipc.client import EthIpc
from mythril.support.loader import DynLoader
from mythril.exceptions import CompilerError
from ethereum import utils
from laser.ethereum import svm, laserfree
from pathlib import Path
@ -152,7 +153,11 @@ elif (len(args.solidity_file)):
for file in args.solidity_file:
file = file.replace("~", str(Path.home())) # Expand user path
name, bytecode = compile_solidity(solc_binary, file)
try:
name, bytecode = compile_solidity(solc_binary, file)
except CompilerError as e:
exitWithError(e)
# Max. 16 contracts supported!
@ -223,7 +228,7 @@ elif (args.graph) or (args.fire_lasers):
else:
laserfree.fire(_svm)
laserfree.fire(modules, contracts[0].address)
else:
parser.print_help()

@ -1,6 +1,7 @@
from ethereum.abi import encode_abi, encode_int
from ethereum.utils import zpad
from ethereum.abi import method_id
from mythril.exceptions import CompilerError
import subprocess
import binascii
import os
@ -15,7 +16,14 @@ def safe_decode(hex_encoded_string):
def compile_solidity(solc_binary, file):
output = subprocess.check_output(["solc", "--bin-runtime", file], stderr=subprocess.DEVNULL)
try:
output = subprocess.check_output(["solc", "--bin-runtime", file], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as exc:
message = "Error compiling input file. solc output:\n" + str(exc.output)
raise CompilerError(message)
except FileNotFoundError:
raise CompilerError("Compiler not found. Make sure that solc is installed and in PATH, or set the SOLC environment variable.")
m = re.search(r":(.*?) =======\\nBinary of the runtime part: \\n([0-9a-f]+)\\n", str(output))
return [m.group(1), m.group(2)]

@ -0,0 +1,2 @@
class CompilerError(Exception):
pass
Loading…
Cancel
Save