Add call stack to RuntimeException based errors
This commit is contained in:
@@ -6,8 +6,11 @@ class SmnpException(Exception):
|
||||
def _title(self):
|
||||
pass
|
||||
|
||||
def _postMessage(self):
|
||||
return ""
|
||||
|
||||
def _position(self):
|
||||
return "" if self.pos is None else f" [line {self.pos[0]+1}, col {self.pos[1]+1}]"
|
||||
|
||||
def message(self):
|
||||
return f"{self._title()}{self._position()}:\n{self.msg}"
|
||||
return f"{self._title()}{self._position()}:\n{self.msg}\n{self._postMessage()}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from smnp.error.base import SmnpException
|
||||
from smnp.error.runtime import RuntimeException
|
||||
|
||||
|
||||
class IllegalFunctionInvocationException(SmnpException):
|
||||
class IllegalFunctionInvocationException(RuntimeException):
|
||||
def __init__(self, expected, found, pos=None):
|
||||
super().__init__(f"Expected signature:\n{expected}\n\nFound:\n{found}", pos)
|
||||
|
||||
@@ -9,7 +9,7 @@ class IllegalFunctionInvocationException(SmnpException):
|
||||
return "Invocation Error"
|
||||
|
||||
|
||||
class FunctionNotFoundException(SmnpException):
|
||||
class FunctionNotFoundException(RuntimeException):
|
||||
def __init__(self, function, pos=None):
|
||||
super().__init__(f"Function '{function}' not found", pos)
|
||||
|
||||
@@ -17,7 +17,7 @@ class FunctionNotFoundException(SmnpException):
|
||||
return "Invocation Error"
|
||||
|
||||
|
||||
class MethodNotFoundException(SmnpException):
|
||||
class MethodNotFoundException(RuntimeException):
|
||||
def __init__(self, object, method, pos=None):
|
||||
super().__init__(f"Method '{method}' of type '{object}' not found", pos)
|
||||
|
||||
@@ -25,7 +25,7 @@ class MethodNotFoundException(SmnpException):
|
||||
return "Invocation Error"
|
||||
|
||||
|
||||
class IllegalArgumentException(SmnpException):
|
||||
class IllegalArgumentException(RuntimeException):
|
||||
def __init__(self, msg, pos=None):
|
||||
super().__init__(msg, pos)
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ class RuntimeException(SmnpException):
|
||||
def _title(self):
|
||||
return "Runtime Error"
|
||||
|
||||
def _postMessage(self):
|
||||
return "\n" + self.environment.callStackToString() if len(self.environment.callStack) > 0 else ""
|
||||
|
||||
# def message(self):
|
||||
# posStr = "" if self.pos is None else f" [line {self.pos[0] + 1}, col {self.pos[1] + 1}]"
|
||||
# return f"Runtime error{posStr}:\n{self.mmsg}"
|
||||
|
||||
Reference in New Issue
Block a user