Skip to content

cleanup of pretty output renderer #708

@sloanlance

Description

@sloanlance

Based on a conversation started in the comments of #706, clean up the appearance of the new pretty output renderer. Pertinent points from the conversation…

  • Fix length of the output dividers (current length is arbitrary; the length of = and - lines do not match)
  • Change to Unicode box characters from ASCII
  • Add vertical space between each error
  • Change exception messages from Python object reprs (with single-quoted strings) to true JSON (with double-quoted strings)
Details I think more important than adding even more output renderers is essentially cleaning up the one new one that was added. Specifically, here's some example output from the new pretty renderer:
⊙  printf '7' | jsonschema --output pretty <(printf '{"minimum": 9, "multipleOf": 3, "not": {"const": 7}}')

===[ValidationError]===(<stdin>)===

7 is less than the minimum of 9

Failed validating 'minimum' in schema:
    {'minimum': 9, 'multipleOf': 3, 'not': {'const': 7}}

On instance:
    7
-----------------------------
===[ValidationError]===(<stdin>)===

7 is not a multiple of 3

Failed validating 'multipleOf' in schema:
    {'minimum': 9, 'multipleOf': 3, 'not': {'const': 7}}

On instance:
    7
-----------------------------
===[ValidationError]===(<stdin>)===

{'const': 7} is not allowed for 7

Failed validating 'not' in schema:
    {'minimum': 9, 'multipleOf': 3, 'not': {'const': 7}}

On instance:
    7
-----------------------------

where some things that rub me a bit wrong visually are:

  • the width of the ascii dividers (right now it's a bit arbitrary and you can see it doesn't match between the = and - lines -- particularly so if it's a SchemaError vs a ValidationError)
  • not using unicode box characters
  • needing a bit of vertical space between each error
  • the fact that, though it's not obvious there, in the exception message, what's there is reprs of Python objects. Even though usually that's what I want shown because jsonschema normally deals with Python objects, not JSON, here that's not the case -- here in fact the reverse is true -- the CLI takes JSON, and does the deserialization itself. So when showing errors back to users of the CLI, it should show JSON, not Python objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions