39 ''' This module provides various error classes used in PSyclone'''
43 '''Utility that defers any computation associated with computing a
44 string until the string is required. This is particularly useful
45 for exceptions, where the string will typically not need to be
46 computed unless the program is about to stop.
48 :param function func: a function that computes a string.
50 :raises TypeError: if the func argument is not a function.
53 def __init__(self, func):
54 if not hasattr(func,
'__call__'):
56 f
"The func argument for the LazyString class should be a "
57 f
"function, but found '{type(func).__name__}'.")
58 self.
_func_func = func
62 :raises TypeError: if the function stored in self._func does \
65 result = self.
_func_func()
66 if not isinstance(result, str):
68 f
"The function supplied to the LazyString class should return "
69 f
"a string, but found '{type(result).__name__}'.")
74 ''' Provides a PSyclone specific error class as a generic parent class for
75 all PSyclone exceptions.
77 :param str value: the message associated with the error.
80 def __init__(self, value):
81 Exception.__init__(self, value)
85 return type(self).__name__ +
"()"
88 return str(self.
valuevalue)
92 ''' Provides a PSyclone specific error class for errors detected when
93 resolving dependencies in the code.
95 :param str value: the message associated with the error.
97 def __init__(self, value):
98 PSycloneError.__init__(self, value)
99 self.
valuevaluevalue =
"UnresolvedDependencyError: "+str(value)
103 ''' Provides a PSyclone specific error class for errors found during PSy
106 :param str value: the message associated with the error.
108 def __init__(self, value):
109 PSycloneError.__init__(self, value)
110 self.
valuevaluevalue =
"Generation Error: "+str(value)
114 ''' Provides a PSyclone-specific error class when a field with the
115 requested property/ies is not found.
117 :param str value: the message associated with the error.
119 def __init__(self, value):
120 PSycloneError.__init__(self, value)
121 self.
valuevaluevalue =
"Field not found error: "+str(value)
126 PSyclone-specific exception for use when an internal error occurs (i.e.
127 something that 'should not happen').
129 :param str value: the message associated with the error.
131 def __init__(self, value):
132 PSycloneError.__init__(self, value)
133 self.
valuevaluevalue =
"PSyclone internal error: "+str(value)
137 __all__ = [
"LazyString",
"PSycloneError",
"GenerationError",
138 "FieldNotFoundError",
"InternalError"]