From 97c18d79dfcb50b3656fe2673e9dfa196d1d8071 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 1 Jun 2020 11:17:27 -0400 Subject: [PATCH] =?utf8?q?Rename=20`msg`/`ctx`=20properties=20=F0=9F=91=89?= =?utf8?q?=20`message`/`context`?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Philippe Proulx --- barectf/cli.py | 6 +++--- barectf/config_parse.py | 38 +++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/barectf/cli.py b/barectf/cli.py index 0d26e82..184218b 100644 --- a/barectf/cli.py +++ b/barectf/cli.py @@ -42,9 +42,9 @@ def _perror(msg): def _pconfig_error(exc): termcolor.cprint('Error:', 'red', file=sys.stderr) - for ctx in reversed(exc.ctx): - if ctx.msg is not None: - msg = f' {ctx.msg}' + for ctx in reversed(exc.context): + if ctx.message is not None: + msg = f' {ctx.message}' else: msg = '' diff --git a/barectf/config_parse.py b/barectf/config_parse.py index 6b45c3f..8457c5a 100644 --- a/barectf/config_parse.py +++ b/barectf/config_parse.py @@ -37,49 +37,49 @@ import os # The context of a configuration parsing error. # # Such a context object has a name and, optionally, a message. -class _ConfigParseErrorCtx: - def __init__(self, name, msg=None): +class _ConfigParseErrorContext: + def __init__(self, name, message=None): self._name = name - self._msg = msg + self._msg = message @property def name(self): return self._name @property - def msg(self): + def message(self): return self._msg # Appends the context having the object name `obj_name` and the -# (optional) message `msg` to the `_ConfigParseError` exception `exc` -# and then raises `exc` again. -def _append_error_ctx(exc, obj_name, msg=None): - exc.append_ctx(obj_name, msg) +# (optional) message `message` to the `_ConfigParseError` exception +# `exc` and then raises `exc` again. +def _append_error_ctx(exc, obj_name, message=None): + exc._append_ctx(obj_name, message) raise # A configuration parsing error. # -# Such an error object contains a list of contexts (`ctx` property). +# Such an error object contains a list of contexts (`context` property). # # The first context of this list is the most specific context, while the # last is the more general. # -# Use append_ctx() to append a context to an existing configuration +# Use _append_ctx() to append a context to an existing configuration # parsing error when you catch it before raising it again. You can use # _append_error_ctx() to do exactly this in a single call. class _ConfigParseError(RuntimeError): - def __init__(self, init_ctx_name, init_ctx_msg=None): + def __init__(self, init_ctx_obj_name, init_ctx_msg=None): self._ctx = [] - self.append_ctx(init_ctx_name, init_ctx_msg) + self._append_ctx(init_ctx_obj_name, init_ctx_msg) @property - def ctx(self): + def context(self): return self._ctx - def append_ctx(self, name, msg=None): - self._ctx.append(_ConfigParseErrorCtx(name, msg)) + def _append_ctx(self, name, msg=None): + self._ctx.append(_ConfigParseErrorContext(name, msg)) def _opt_to_public(obj): @@ -470,7 +470,7 @@ class _SchemaValidator: f'{exc.message}{schema_ctx} (from schema `{schema_short_id}`)') for ctx in reversed(contexts): - new_exc.append_ctx(ctx) + new_exc._append_ctx(ctx) raise new_exc @@ -861,7 +861,7 @@ class _YamlConfigParser: if clock is None: exc = _ConfigParseError('`property-mappings` property', f'Clock type `{clock_name}` does not exist') - exc.append_ctx('Integer field type') + exc._append_ctx('Integer field type') raise exc prop_mapping = _PropertyMapping() @@ -985,7 +985,7 @@ class _YamlConfigParser: if mn > mx: exc = _ConfigParseError(ctx_obj_name) - exc.append_ctx(f'Member `{label}`', + exc._append_ctx(f'Member `{label}`', f'Invalid integral range ({mn} > {mx})') raise exc @@ -1847,7 +1847,7 @@ class _YamlConfigParser: if ll_node not in log_levels_node: exc = _ConfigParseError('`log-level` property', f'Log level alias `{ll_node}` does not exist') - exc.append_ctx(f'Event type `{event_name}`') + exc._append_ctx(f'Event type `{event_name}`') raise exc event[prop_name] = log_levels_node[ll_node] -- 2.34.1