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 error readability #74

Merged
merged 1 commit into from
Nov 6, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/odm_sharing/private/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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__

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/odm_sharing/private/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/odm_sharing/private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}'


Expand Down
Loading