Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve launch file parsing error messages #626

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions launch/launch/invalid_launch_file_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def __init__(self, extension='', *, likely_errors=None):
)
else:
self._error_message = (
'Caught exception when trying to load file of format [{}]: {}'
).format(self._extension, self._likely_errors[0])
'Caught {} when trying to load file of format [{}]:'
).format('multiple exceptions' if len(self._likely_errors) > 1 else 'exception',
self._extension)
for error in self._likely_errors:
self._error_message += '\n - {}'.format(error)

self.__cause__ = self._likely_errors[0]

def __str__(self):
Expand Down
6 changes: 3 additions & 3 deletions launch_xml/launch_xml/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_attr(
If coercion fails, `ValueError` will be raised.
"""
attr_error = AttributeError(
'Attribute {} of type {} not found in Entity {}'.format(
"Attribute '{}' of type '{}' not found in Entity '{}'".format(
name, data_type, self.type_name
)
)
Expand Down Expand Up @@ -123,8 +123,8 @@ def get_attr(
value = get_typed_value(value, data_type, can_be_str=can_be_str)
except ValueError:
raise TypeError(
'Attribute {} of Entity {} expected to be of type {}.'
'`{}` can not be converted to one of those types'.format(
"Attribute '{}' of Entity '{}' expected to be of type '{}'."
"'{}' can not be converted to one of those types".format(
name, self.type_name, data_type, value
)
)
Expand Down
6 changes: 3 additions & 3 deletions launch_yaml/launch_yaml/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_attr(
if name not in self.__element:
if not optional:
raise AttributeError(
'Can not find attribute {} in Entity {}'.format(
"Can not find attribute '{}' in Entity '{}'".format(
name, self.type_name))
else:
return None
Expand All @@ -126,13 +126,13 @@ def get_attr(
if isinstance(data, list) and isinstance(data[0], dict):
return [Entity(child, name) for child in data]
raise TypeError(
'Attribute {} of Entity {} expected to be a list of dictionaries.'.format(
"Attribute '{}' of Entity '{}' expected to be a list of dictionaries.".format(
name, self.type_name
)
)
if not is_instance_of(data, data_type, can_be_str=can_be_str):
raise TypeError(
'Attribute {} of Entity {} expected to be of type {}, got {}'.format(
"Attribute '{}' of Entity '{}' expected to be of type '{}', got '{}'".format(
name, self.type_name, data_type, type(data)
)
)
Expand Down