clkhash icon indicating copy to clipboard operation
clkhash copied to clipboard

Error message for invalid schema could be more helpful

Open wilko77 opened this issue 7 years ago • 0 comments

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

wilko77 avatar Jun 04 '18 00:06 wilko77