Improve exceptions catching

pull/264/head
Josselin 6 years ago
parent 00ee4637b8
commit 6d86220a53
  1. 6
      slither/core/cfg/node.py
  2. 3
      slither/solc_parsing/declarations/function.py
  3. 10
      slither/utils/expression_manipulations.py

@ -20,6 +20,7 @@ from slither.slithir.operations import (Balance, HighLevelCall, Index,
from slither.slithir.variables import (Constant, LocalIRVariable,
ReferenceVariable, StateIRVariable,
TemporaryVariable, TupleVariable)
from slither.all_exceptions import SlitherException
logger = logging.getLogger("Node")
@ -715,7 +716,10 @@ class Node(SourceMapping, ChildFunction):
elif ir.destination == SolidityVariable('this'):
self._high_level_calls.append((self.function.contract, ir.function))
else:
self._high_level_calls.append((ir.destination.type.type, ir.function))
try:
self._high_level_calls.append((ir.destination.type.type, ir.function))
except AttributeError:
raise SlitherException(f'Function not found on {ir}. Please try compiling with a recent Solidity version.')
elif isinstance(ir, LibraryCall):
assert isinstance(ir.destination, Contract)
self._high_level_calls.append((ir.destination, ir.function))

@ -966,7 +966,8 @@ class FunctionSolc(Function):
if has_cond.result():
st = SplitTernaryExpression(node.expression)
condition = st.condition
assert condition
if not condition:
raise ParsingError(f'Incorrect ternary conversion {node.expression} {node.source_mapping_str}')
true_expr = st.true_expression
false_expr = st.false_expression
self.split_ternary_node(node, condition, true_expr, false_expr)

@ -7,17 +7,15 @@ from slither.core.expressions.assignment_operation import AssignmentOperation
from slither.core.expressions.binary_operation import BinaryOperation
from slither.core.expressions.call_expression import CallExpression
from slither.core.expressions.conditional_expression import ConditionalExpression
from slither.core.expressions.elementary_type_name_expression import ElementaryTypeNameExpression
from slither.core.expressions.identifier import Identifier
from slither.core.expressions.index_access import IndexAccess
from slither.core.expressions.literal import Literal
from slither.core.expressions.member_access import MemberAccess
from slither.core.expressions.new_array import NewArray
from slither.core.expressions.new_contract import NewContract
from slither.core.expressions.new_elementary_type import NewElementaryType
from slither.core.expressions.tuple_expression import TupleExpression
from slither.core.expressions.type_conversion import TypeConversion
from slither.core.expressions.unary_operation import UnaryOperation
from slither.all_exceptions import SlitherException
def f_expressions(e, x):
e._expressions.append(x)
@ -35,8 +33,6 @@ class SplitTernaryExpression(object):
def __init__(self, expression):
# print(expression)
if isinstance(expression, ConditionalExpression):
self.true_expression = copy.copy(expression.then_expression)
self.false_expression = copy.copy(expression.else_expression)
@ -64,7 +60,7 @@ class SplitTernaryExpression(object):
return
if isinstance(expression, ConditionalExpression):
raise Exception('Nested ternary operator not handled')
raise SlitherException('Nested ternary operator not handled')
if isinstance(expression, (Literal, Identifier, IndexAccess, NewArray, NewContract)):
return None
@ -117,5 +113,5 @@ class SplitTernaryExpression(object):
false_expression.expression)
else:
raise Exception('Ternary operation not handled {}({})'.format(expression, type(expression)))
raise SlitherException('Ternary operation not handled {}({})'.format(expression, type(expression)))

Loading…
Cancel
Save