From 2c4d02cfadfa111048153912d75fc96c0770b2bd Mon Sep 17 00:00:00 2001 From: zargot Date: Wed, 6 Nov 2024 11:21:36 -0500 Subject: [PATCH] improve error readability --- src/odm_sharing/private/rules.py | 8 ++++---- src/odm_sharing/private/trees.py | 2 +- src/odm_sharing/private/utils.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/odm_sharing/private/rules.py b/src/odm_sharing/private/rules.py index fc815258..f5b9ba7d 100644 --- a/src/odm_sharing/private/rules.py +++ b/src/odm_sharing/private/rules.py @@ -88,8 +88,8 @@ class ParseError(Exception): def gen_error(ctx: SchemaCtx, desc: str) -> ParseError: '''returns a ParseError''' - col = f',{ctx.column}' if ctx.column else '' - msg = f'{ctx.filename}({ctx.line_num}{col}): {desc}' + col = f', col: {qt(ctx.column)}' if ctx.column else '' + msg = f'{ctx.filename}(ln: {ctx.line_num}{col}): {desc}' print('Error: ' + msg, file=sys.stderr) return ParseError(msg) @@ -117,7 +117,7 @@ def coerce_value( # type: ignore def get_expected(type_class) -> str: # type: ignore if type(type_class) is EnumMeta: - return fmt_set(list(type_class)) + return 'one of ' + fmt_set(list(type_class)) else: return type_class.__name__ @@ -185,7 +185,7 @@ def check_required(ctx: SchemaCtx, val: str, mode: RuleMode, def check_set(ctx: SchemaCtx, actual: str, expected: Union[set, list] ) -> None: if actual not in expected: - err(f'got {qt(actual)}, expected {fmt_set(expected)}') + err(f'got {qt(actual)}, expected one of {fmt_set(expected)}') ctx.column = RULE_ID if rule.id <= 0: diff --git a/src/odm_sharing/private/trees.py b/src/odm_sharing/private/trees.py index 1ff011e2..fb8a64d6 100644 --- a/src/odm_sharing/private/trees.py +++ b/src/odm_sharing/private/trees.py @@ -108,7 +108,7 @@ def __init__(self, filename: str) -> None: def gen_error(ctx: Ctx, desc: str) -> ParseError: - loc = f'(rule {ctx.rule_id})' if ctx.rule_id else '' + loc = f'(id: {ctx.rule_id})' if ctx.rule_id else '' msg = f'{ctx.filename}{loc}: {desc}' print('Error: ' + msg, file=sys.stderr) return ParseError(msg) diff --git a/src/odm_sharing/private/utils.py b/src/odm_sharing/private/utils.py index 4b8c4ff3..f99cfaee 100644 --- a/src/odm_sharing/private/utils.py +++ b/src/odm_sharing/private/utils.py @@ -20,7 +20,7 @@ def not_empty(x: Union[list, set, str]) -> bool: def fmt_set(values: Iterable) -> str: '''returns a comma-separated string of the items in `values`, surrounded by curly-brackets''' - items = ','.join(map(qt, values)) + items = ', '.join(values) return f'{{{items}}}'