remove passive aggressiveness from error messages
Change-Id: I6a25703c65c11c1b57e2cad409b0da0bba724b5e Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/37841 Reviewed-by: Georg Brandl <g.brandl@fz-juelich.de> Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
@@ -238,7 +238,7 @@ class FloatRange(HasUnit, DataType):
|
|||||||
self.default = 0 if self.min <= 0 <= self.max else self.min
|
self.default = 0 if self.min <= 0 <= self.max else self.min
|
||||||
super().checkProperties()
|
super().checkProperties()
|
||||||
if '%' not in self.fmtstr:
|
if '%' not in self.fmtstr:
|
||||||
raise ConfigError('Invalid fmtstr!')
|
raise ConfigError('Invalid fmtstr')
|
||||||
|
|
||||||
def export_datatype(self):
|
def export_datatype(self):
|
||||||
return self.get_info(type='double')
|
return self.get_info(type='double')
|
||||||
@@ -411,7 +411,7 @@ class ScaledInteger(HasUnit, DataType):
|
|||||||
|
|
||||||
# check values
|
# check values
|
||||||
if '%' not in self.fmtstr:
|
if '%' not in self.fmtstr:
|
||||||
raise ConfigError('Invalid fmtstr!')
|
raise ConfigError('Invalid fmtstr')
|
||||||
# Remark: Datatype.copy() will round min, max to a multiple of self.scale
|
# Remark: Datatype.copy() will round min, max to a multiple of self.scale
|
||||||
# this should be o.k.
|
# this should be o.k.
|
||||||
|
|
||||||
@@ -646,22 +646,22 @@ class StringType(DataType):
|
|||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
"""accepts strings only"""
|
"""accepts strings only"""
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
raise WrongTypeError(f'{shortrepr(value)} has the wrong type!')
|
raise WrongTypeError(f'{shortrepr(value)} has the wrong type')
|
||||||
if not self.isUTF8:
|
if not self.isUTF8:
|
||||||
try:
|
try:
|
||||||
value.encode('ascii')
|
value.encode('ascii')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
raise RangeError(f'{shortrepr(value)} contains non-ascii character!') from None
|
raise RangeError(f'{shortrepr(value)} contains non-ascii character') from None
|
||||||
size = len(value)
|
size = len(value)
|
||||||
if size < self.minchars:
|
if size < self.minchars:
|
||||||
raise RangeError(
|
raise RangeError(
|
||||||
f'{shortrepr(value)} must be at least {self.minchars} chars long!')
|
f'{shortrepr(value)} must be at least {self.minchars} chars long')
|
||||||
if size > self.maxchars:
|
if size > self.maxchars:
|
||||||
raise RangeError(
|
raise RangeError(
|
||||||
f'{shortrepr(value)} must be at most {self.maxchars} chars long!')
|
f'{shortrepr(value)} must be at most {self.maxchars} chars long')
|
||||||
if '\0' in value:
|
if '\0' in value:
|
||||||
raise RangeError(
|
raise RangeError(
|
||||||
'Strings are not allowed to embed a \\0! Use a Blob instead!')
|
'Strings are not allowed to embed a \\0! Use a Blob instead')
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def export_value(self, value):
|
def export_value(self, value):
|
||||||
@@ -724,12 +724,12 @@ class BoolType(DataType):
|
|||||||
return False
|
return False
|
||||||
if value in ['1', 'True', 'true', 'yes', 'on']:
|
if value in ['1', 'True', 'true', 'yes', 'on']:
|
||||||
return True
|
return True
|
||||||
raise WrongTypeError(f'{shortrepr(value)} is not a boolean value!')
|
raise WrongTypeError(f'{shortrepr(value)} is not a boolean value')
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
if value in (0, 1):
|
if value in (0, 1):
|
||||||
return bool(value)
|
return bool(value)
|
||||||
raise WrongTypeError(f'{shortrepr(value)} is not a boolean value!')
|
raise WrongTypeError(f'{shortrepr(value)} is not a boolean value')
|
||||||
|
|
||||||
def export_value(self, value):
|
def export_value(self, value):
|
||||||
"""returns a python object fit for serialisation"""
|
"""returns a python object fit for serialisation"""
|
||||||
@@ -764,7 +764,7 @@ class ArrayOf(DataType):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
if not isinstance(members, DataType):
|
if not isinstance(members, DataType):
|
||||||
raise ProgrammingError(
|
raise ProgrammingError(
|
||||||
'ArrayOf only works with a DataType as first argument!')
|
'ArrayOf only works with a DataType as first argument')
|
||||||
# one argument -> exactly that size
|
# one argument -> exactly that size
|
||||||
# argument default to 100
|
# argument default to 100
|
||||||
if maxlen is None:
|
if maxlen is None:
|
||||||
@@ -810,12 +810,12 @@ class ArrayOf(DataType):
|
|||||||
# check number of elements
|
# check number of elements
|
||||||
if self.minlen is not None and len(value) < self.minlen:
|
if self.minlen is not None and len(value) < self.minlen:
|
||||||
raise RangeError(
|
raise RangeError(
|
||||||
f'array too small, needs at least {self.minlen} elements!')
|
f'array too small, needs at least {self.minlen} elements')
|
||||||
if self.maxlen is not None and len(value) > self.maxlen:
|
if self.maxlen is not None and len(value) > self.maxlen:
|
||||||
raise RangeError(
|
raise RangeError(
|
||||||
f'array too big, holds at most {self.maxlen} elements!')
|
f'array too big, holds at most {self.maxlen} elements')
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise WrongTypeError(f'{type(value).__name__} can not be converted to ArrayOf DataType!') from None
|
raise WrongTypeError(f'{type(value).__name__} can not be converted to ArrayOf DataType') from None
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
"""accepts any sequence, converts to tuple (immutable!)"""
|
"""accepts any sequence, converts to tuple (immutable!)"""
|
||||||
@@ -881,11 +881,11 @@ class TupleOf(DataType):
|
|||||||
def __init__(self, *members):
|
def __init__(self, *members):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
if not members:
|
if not members:
|
||||||
raise ProgrammingError('Empty tuples are not allowed!')
|
raise ProgrammingError('Empty tuples are not allowed')
|
||||||
for subtype in members:
|
for subtype in members:
|
||||||
if not isinstance(subtype, DataType):
|
if not isinstance(subtype, DataType):
|
||||||
raise ProgrammingError(
|
raise ProgrammingError(
|
||||||
'TupleOf only works with DataType objs as arguments!')
|
'TupleOf only works with DataType objs as arguments')
|
||||||
self.members = members
|
self.members = members
|
||||||
self.default = tuple(el.default for el in members)
|
self.default = tuple(el.default for el in members)
|
||||||
|
|
||||||
@@ -904,7 +904,7 @@ class TupleOf(DataType):
|
|||||||
if len(value) == len(self.members):
|
if len(value) == len(self.members):
|
||||||
return
|
return
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise WrongTypeError(f'{type(value).__name__} can not be converted to TupleOf DataType!') from None
|
raise WrongTypeError(f'{type(value).__name__} can not be converted to TupleOf DataType') from None
|
||||||
raise WrongTypeError(f'tuple needs {len(self.members)} elements')
|
raise WrongTypeError(f'tuple needs {len(self.members)} elements')
|
||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
@@ -969,16 +969,16 @@ class StructOf(DataType):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.members = members
|
self.members = members
|
||||||
if not members:
|
if not members:
|
||||||
raise ProgrammingError('Empty structs are not allowed!')
|
raise ProgrammingError('Empty structs are not allowed')
|
||||||
self.optional = list(members if optional is None else optional)
|
self.optional = list(members if optional is None else optional)
|
||||||
for name, subtype in list(members.items()):
|
for name, subtype in list(members.items()):
|
||||||
if not isinstance(subtype, DataType):
|
if not isinstance(subtype, DataType):
|
||||||
raise ProgrammingError(
|
raise ProgrammingError(
|
||||||
'StructOf only works with named DataType objs as keyworded arguments!')
|
'StructOf only works with named DataType objs as keyworded arguments')
|
||||||
for name in self.optional:
|
for name in self.optional:
|
||||||
if name not in members:
|
if name not in members:
|
||||||
raise ProgrammingError(
|
raise ProgrammingError(
|
||||||
'Only members of StructOf may be declared as optional!')
|
'Only members of StructOf may be declared as optional')
|
||||||
self.default = dict((k, el.default) for k, el in members.items())
|
self.default = dict((k, el.default) for k, el in members.items())
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
@@ -1082,10 +1082,10 @@ class CommandType(DataType):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
if argument is not None:
|
if argument is not None:
|
||||||
if not isinstance(argument, DataType):
|
if not isinstance(argument, DataType):
|
||||||
raise ProgrammingError('CommandType: Argument type must be a DataType!')
|
raise ProgrammingError('CommandType: Argument type must be a DataType')
|
||||||
if result is not None:
|
if result is not None:
|
||||||
if not isinstance(result, DataType):
|
if not isinstance(result, DataType):
|
||||||
raise ProgrammingError('CommandType: Result type must be a DataType!')
|
raise ProgrammingError('CommandType: Result type must be a DataType')
|
||||||
self.argument = argument
|
self.argument = argument
|
||||||
self.result = result
|
self.result = result
|
||||||
|
|
||||||
@@ -1107,10 +1107,10 @@ class CommandType(DataType):
|
|||||||
raise ProgrammingError('commands can not be converted to a value')
|
raise ProgrammingError('commands can not be converted to a value')
|
||||||
|
|
||||||
def export_value(self, value):
|
def export_value(self, value):
|
||||||
raise ProgrammingError('values of type command can not be transported!')
|
raise ProgrammingError('values of type command can not be transported')
|
||||||
|
|
||||||
def import_value(self, value):
|
def import_value(self, value):
|
||||||
raise ProgrammingError('values of type command can not be transported!')
|
raise ProgrammingError('values of type command can not be transported')
|
||||||
|
|
||||||
def from_string(self, text):
|
def from_string(self, text):
|
||||||
raise ProgrammingError('a string can not be converted to a command')
|
raise ProgrammingError('a string can not be converted to a command')
|
||||||
|
|||||||
Reference in New Issue
Block a user