return prop_name
+def _append_error_ctx(exc, obj_name, msg=None):
+ exc.append_ctx(obj_name, msg)
+ raise
+
+
# This validator validates the configured metadata for barectf specific
# needs.
#
try:
self._validate_type(field_type, False)
except ConfigParseError as exc:
- exc.append_ctx('Structure type\' field "{}"'.format(field_name))
- raise
+ _append_error_ctx(exc, 'Structure type\' field "{}"'.format(field_name))
def _validate_array_type(self, t, entity_root):
raise ConfigParseError('Array type', 'Not supported as of this version')
try:
self._validate_entity(meta.trace.packet_header_type)
except ConfigParseError as exc:
- exc.append_ctx('Trace', 'Invalid packet header type')
- raise
+ _append_error_ctx(exc, 'Trace', 'Invalid packet header type')
for stream_name, stream in meta.streams.items():
if not _is_valid_identifier(stream_name):
try:
self._validate_entity(stream.packet_context_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid packet context type')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid packet context type')
self._cur_entity = _Entity.STREAM_EVENT_HEADER
try:
self._validate_entity(stream.event_header_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid event header type')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid event header type')
self._cur_entity = _Entity.STREAM_EVENT_CONTEXT
try:
self._validate_entity(stream.event_context_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid event context type'.format(stream_name))
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid event context type'.format(stream_name))
try:
for ev_name, ev in stream.events.items():
try:
self._validate_entity(ev.context_type)
except ConfigParseError as exc:
- exc.append_ctx('Event "{}"'.format(ev_name),
- 'Invalid context type')
- raise
+ _append_error_ctx(exc, 'Event "{}"'.format(ev_name),
+ 'Invalid context type')
self._cur_entity = _Entity.EVENT_PAYLOAD
try:
self._validate_entity(ev.payload_type)
except ConfigParseError as exc:
- exc.append_ctx('Event "{}"'.format(ev_name),
- 'Invalid payload type')
- raise
+ _append_error_ctx(exc, 'Event "{}"'.format(ev_name),
+ 'Invalid payload type')
if stream.is_event_empty(ev):
raise ConfigParseError('Event "{}"'.format(ev_name), 'Empty')
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name))
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name))
def _validate_default_stream(self, meta):
if meta.default_stream_name:
try:
self._validate_stream(stream)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream.name), 'Invalid')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream.name), 'Invalid')
# Entities. Order of values is important here.
try:
self._validate_type_histology(field_type)
except ConfigParseError as exc:
- exc.append_ctx('Structure type\'s field "{}"'.format(field_name))
- raise
+ _append_error_ctx(exc, 'Structure type\'s field "{}"'.format(field_name))
def _validate_array_histology(self, t):
# length is set
try:
self._validate_type_histology(t.element_type)
except ConfigParseError as exc:
- exc.append_ctx('Array type', 'Invalid element type')
- raise
+ _append_error_ctx(exc, 'Array type', 'Invalid element type')
def _validate_type_histology(self, t):
if t is None:
try:
self._validate_entity_type_histology(ev.context_type)
except ConfigParseError as exc:
- exc.append_ctx('Event "{}"'.format(ev.name),
- 'Invalid context type')
- raise
+ _append_error_ctx(exc, 'Event "{}"'.format(ev.name),
+ 'Invalid context type')
# validate event payload type
try:
self._validate_entity_type_histology(ev.payload_type)
except ConfigParseError as exc:
- exc.append_ctx('Event "{}"'.format(ev.name),
- 'Invalid payload type')
- raise
+ _append_error_ctx(exc, 'Event "{}"'.format(ev.name),
+ 'Invalid payload type')
def _validate_stream_types_histology(self, stream):
stream_name = stream.name
try:
self._validate_entity_type_histology(stream.packet_context_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid packet context type')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid packet context type')
# validate stream event header type
try:
self._validate_entity_type_histology(stream.event_header_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid event header type')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid event header type')
# validate stream event context type
try:
self._validate_entity_type_histology(stream.event_context_type)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid event context type')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid event context type')
# validate events
for ev in stream.events.values():
try:
self._validate_event_types_histology(ev)
except ConfigParseError as exc:
- exc.append_ctx('Stream "{}"'.format(stream_name),
- 'Invalid event')
- raise
+ _append_error_ctx(exc, 'Stream "{}"'.format(stream_name),
+ 'Invalid event')
def validate(self, meta):
# validate trace packet header type
try:
self._validate_entity_type_histology(meta.trace.packet_header_type)
except ConfigParseError as exc:
- exc.append_ctx('Metadata\'s trace', 'Invalid packet header type')
- raise
+ _append_error_ctx(exc, 'Metadata\'s trace', 'Invalid packet header type')
# validate streams
for stream in meta.streams.values():
try:
obj.value_type = self._create_type(value_type_node)
except ConfigParseError as exc:
- exc.append_ctx('Enumeration type', 'Cannot create integer type')
- raise
+ _append_error_ctx(exc, 'Enumeration type', 'Cannot create integer type')
# members
if 'members' in node:
try:
obj.fields[field_name] = self._create_type(field_node)
except ConfigParseError as exc:
- exc.append_ctx('Structure type',
- 'Cannot create field "{}"'.format(field_name))
- raise
+ _append_error_ctx(exc, 'Structure type',
+ 'Cannot create field "{}"'.format(field_name))
return obj
try:
obj.element_type = self._create_type(node['element-type'])
except ConfigParseError as exc:
- exc.append_ctx('Array type', 'Cannot create element type')
- raise
+ _append_error_ctx(exc, 'Array type', 'Cannot create element type')
return obj
try:
t = self._create_type(ta_type)
except ConfigParseError as exc:
- exc.append_ctx('Metadata',
- 'Cannot create type alias "{}"'.format(ta_name))
- raise
+ _append_error_ctx(exc, 'Metadata',
+ 'Cannot create type alias "{}"'.format(ta_name))
self._tas[ta_name] = t
try:
clock = self._create_clock(clock_node)
except ConfigParseError as exc:
- exc.append_ctx('Metadata',
- 'Cannot create clock "{}"'.format(clock_name))
- raise
+ _append_error_ctx(exc, 'Metadata',
+ 'Cannot create clock "{}"'.format(clock_name))
clock.name = clock_name
self._clocks[clock_name] = clock
try:
ph_type = self._create_type(trace_node['packet-header-type'])
except ConfigParseError as exc:
- exc.append_ctx('Trace',
- 'Cannot create packet header type')
- raise
+ _append_error_ctx(exc, 'Trace',
+ 'Cannot create packet header type')
trace.packet_header_type = ph_type
try:
t = self._create_type(event_node['context-type'])
except ConfigParseError as exc:
- exc.append_ctx('Event',
- 'Cannot create context type object')
- raise
+ _append_error_ctx(exc, 'Event',
+ 'Cannot create context type object')
event.context_type = t
try:
t = self._create_type(event_node['payload-type'])
except ConfigParseError as exc:
- exc.append_ctx('Event',
- 'Cannot create payload type object')
- raise
+ _append_error_ctx(exc, 'Event',
+ 'Cannot create payload type object')
event.payload_type = t
try:
t = self._create_type(stream_node['packet-context-type'])
except ConfigParseError as exc:
- exc.append_ctx('Stream',
- 'Cannot create packet context type object')
- raise
+ _append_error_ctx(exc, 'Stream',
+ 'Cannot create packet context type object')
stream.packet_context_type = t
try:
t = self._create_type(stream_node['event-header-type'])
except ConfigParseError as exc:
- exc.append_ctx('Stream',
- 'Cannot create event header type object')
- raise
+ _append_error_ctx(exc, 'Stream',
+ 'Cannot create event header type object')
stream.event_header_type = t
try:
t = self._create_type(stream_node['event-context-type'])
except ConfigParseError as exc:
- exc.append_ctx('Stream',
- 'Cannot create event context type object')
- raise
+ _append_error_ctx(exc, 'Stream',
+ 'Cannot create event context type object')
stream.event_context_type = t
try:
ev = self._create_event(ev_node)
except ConfigParseError as exc:
- exc.append_ctx('Stream',
- 'Cannot create event "{}"'.format(ev_name))
- raise
+ _append_error_ctx(exc, 'Stream',
+ 'Cannot create event "{}"'.format(ev_name))
ev.id = cur_id
ev.name = ev_name
try:
stream = self._create_stream(stream_name, stream_node)
except ConfigParseError as exc:
- exc.append_ctx('Metadata',
- 'Cannot create stream "{}"'.format(stream_name))
- raise
+ _append_error_ctx(exc, 'Metadata',
+ 'Cannot create stream "{}"'.format(stream_name))
stream.id = cur_id
stream.name = str(stream_name)
validator = _MetadataSpecialFieldsValidator()
validator.validate(self._meta)
except ConfigParseError as exc:
- exc.append_ctx('Metadata')
- raise
+ _append_error_ctx(exc, 'Metadata')
try:
validator = _BarectfMetadataValidator()
validator.validate(self._meta)
except ConfigParseError as exc:
- exc.append_ctx('barectf metadata')
- raise
+ _append_error_ctx(exc, 'barectf metadata')
return self._meta
try:
overlay_node = process_base_include_cb(overlay_node)
except ConfigParseError as exc:
- exc.append_ctx('In "{}"'.format(cur_base_path))
- raise
+ _append_error_ctx(exc, 'In "{}"'.format(cur_base_path))
# pop include stack now that we're done including
del self._include_stack[-1]
try:
events_node[key] = self._process_event_include(event_node)
except ConfigParseError as exc:
- exc.append_ctx('"$include" property',
- 'Cannot process includes of event object "{}"'.format(key))
- raise
+ _append_error_ctx(exc, '"$include" property',
+ 'Cannot process includes of event object "{}"'.format(key))
return self._process_node_include(stream_node, 'stream',
self._process_stream_include,
try:
clocks_node[key] = self._process_clock_include(clock_node)
except ConfigParseError as exc:
- exc.append_ctx('"$include" property',
- 'Cannot process includes of clock object "{}"'.format(key))
- raise
+ _append_error_ctx(exc, '"$include" property',
+ 'Cannot process includes of clock object "{}"'.format(key))
if 'streams' in metadata_node:
streams_node = metadata_node['streams']
try:
streams_node[key] = self._process_stream_include(stream_node)
except ConfigParseError as exc:
- exc.append_ctx('"$include" property',
- 'Cannot process includes of stream object "{}"'.format(key))
- raise
+ _append_error_ctx(exc, '"$include" property',
+ 'Cannot process includes of stream object "{}"'.format(key))
return self._process_node_include(metadata_node, 'metadata',
self._process_metadata_include,
raise ConfigParseError('Configuration',
'Cannot open file "{}"'.format(yaml_path))
except ConfigParseError as exc:
- exc.append_ctx('Configuration',
- 'Unknown error while trying to load file "{}"'.format(yaml_path))
- raise
+ _append_error_ctx(exc, 'Configuration',
+ 'Unknown error while trying to load file "{}"'.format(yaml_path))
# loaded node must be an associate array
if not _is_assoc_array_prop(node):
try:
root = self._yaml_ordered_load(yaml_path)
except ConfigParseError as exc:
- exc.append_ctx('Configuration',
- 'Cannot parse YAML file "{}"'.format(yaml_path))
- raise
+ _append_error_ctx(exc, 'Configuration',
+ 'Cannot parse YAML file "{}"'.format(yaml_path))
if not _is_assoc_array_prop(root):
raise ConfigParseError('Configuration',
dump_config)
return parser.parse(path)
except ConfigParseError as exc:
- exc.append_ctx('Configuration',
- 'Cannot create configuration from YAML file "{}"'.format(path))
- raise
+ _append_error_ctx(exc, 'Configuration',
+ 'Cannot create configuration from YAML file "{}"'.format(path))