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

Error message for invalid schema could be more helpful #155

Open
wilko77 opened this issue Jun 4, 2018 · 0 comments
Open

Error message for invalid schema could be more helpful #155

wilko77 opened this issue Jun 4, 2018 · 0 comments

Comments

@wilko77
Copy link
Collaborator

wilko77 commented Jun 4, 2018

This is what you get:

Traceback (most recent call last):
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/clkhash/schema.py", line 268, in validate_schema_dict
    jsonschema.validate(schema, master_schema)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/jsonschema/validators.py", line 541, in validate
    cls(schema, *args, **kwargs).validate(instance)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/jsonschema/validators.py", line 130, in validate
    raise error
jsonschema.exceptions.ValidationError: {'identifier': 'Date_of_birth', 'description': 'JL DATE_OF_BIRTH and FACS DOB - blanks in JL', 'format': {'type': 'date', 'description': 'YYYY-MM-DD in both source files', 'encoding': 'utf-8', 'format': '%Y-%m-%d'}, 'hashing': {'ngram': 2, 'weight': 1, 'positional': True}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['features']['items']:
    {'oneOf': [{'$ref': '#/definitions/featureConfig'},
               {'$ref': '#/definitions/ignoreFeature'}],
     'type': 'object'}

On instance['features'][5]:
    {'description': 'JL DATE_OF_BIRTH and FACS DOB - blanks in JL',
     'format': {'description': 'YYYY-MM-DD in both source files',
                'encoding': 'utf-8',
                'format': '%Y-%m-%d',
                'type': 'date'},
     'hashing': {'ngram': 2, 'positional': True, 'weight': 1},
     'identifier': 'Date_of_birth'}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/bin/clkutil", line 11, in <module>
    sys.exit(cli())
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/clkhash/cli.py", line 72, in hash
    schema_object = clkhash.schema.Schema.from_json_file(schema_file=schema)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/clkhash/schema.py", line 196, in from_json_file
    return cls.from_json_dict(schema_dict, validate=validate)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/clkhash/schema.py", line 168, in from_json_dict
    validate_schema_dict(schema_dict)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/clkhash/schema.py", line 270, in validate_schema_dict
    raise_from(SchemaError('The schema is not valid.'), e)
  File "/Users/hen271/.local/share/virtualenvs/clkhash-doj/lib/python3.6/site-packages/future/utils/__init__.py", line 398, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
clkhash.schema.SchemaError: The schema is not valid.

Keep in mind that the user only sees the last few lines (depending on his terminal config) and thus might not see the actual cause for the Error.
I would prefer if the output looked more like this:

jsonschema.exceptions.ValidationError: {'identifier': 'Date_of_birth', 'description': 'JL DATE_OF_BIRTH and FACS DOB - blanks in JL', 'format': {'type': 'date', 'description': 'YYYY-MM-DD in both source files', 'encoding': 'utf-8', 'format': '%Y-%m-%d'}, 'hashing': {'ngram': 2, 'weight': 1, 'positional': True}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['features']['items']:
    {'oneOf': [{'$ref': '#/definitions/featureConfig'},
               {'$ref': '#/definitions/ignoreFeature'}],
     'type': 'object'}

On instance['features'][5]:
    {'description': 'JL DATE_OF_BIRTH and FACS DOB - blanks in JL',
     'format': {'description': 'YYYY-MM-DD in both source files',
                'encoding': 'utf-8',
                'format': '%Y-%m-%d',
                'type': 'date'},
     'hashing': {'ngram': 2, 'positional': True, 'weight': 1},
     'identifier': 'Date_of_birth'}

clkhash.schema.SchemaError: The schema is not valid.

Aha! Link: https://csiro.aha.io/features/ANONLINK-28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant