-
Notifications
You must be signed in to change notification settings - Fork 4
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
[WIP] Improve validation error messages #8
Conversation
bf659ff
to
f17b94f
Compare
f17b94f
to
cf824e8
Compare
This PR has had the work on themeing and rewording validation errors added to it. See openownership/cove-bods#16 (comment) for more info. There's a fixture file to display all the errors in the lib-cove-bods repo: https://github.com/openownership/lib-cove-bods/pull/5/files#diff-8a78820a9db4bf7876c2083f107362f9 |
fe0ec37
to
cf824e8
Compare
Currently this PR is held up by considering what affect these changes have on 360Giving and OCDS. |
@jpmckinney We have slightly reworded validation error messages, for the Beneficial Ownership Data Standard data review tool. This is mostly to say "should be" rather than "is not". By default these changes will apply to OCDS too, but it's possible for each CoVE instance to have a separate set of messages. Here's the changes in the code https://github.com/OpenDataServices/lib-cove/pull/8/files#diff-6a1b32728accbec582a1c06a7bdddda7L32 For OCDS this is what the new messages look like: Here's the same file in the current CoVE deploy: What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is not" and "should be" are not interchangeable semantically. For example, it is correct to say "123
is not a string". But "123
should be a string" is, at least, awkward. 123
is a number, and nothing can ever make it a string. What is meant is "the value of field X should be a string (current value is 123
)". The value of a field can have different types, but 123
will always have the number type…
So, I prefer "is not" if the subject of the sentence is a value. If the subject is a field, then "should be" works.
Update: Looking at the web UI, I can't tell which of these format strings are substituted with field names and which are substituted with values. The same CSS style is applied to both in the UI, which is confusing. So, some comments may or may not be relevant depending on what's being substituted.
That said, we should ideally have different styles for values versus fields, as this is an important distinction. Perhaps fields can have no background color, and values can have a background color (with both otherwise using the same monotype font)?
'date': 'Date is not in the correct format. The correct format is YYYY-MM-DD.', | ||
'date-time': 'Date is not in the correct format. The correct format is YYYY-MM-DDThh:mm:ssZ.', | ||
'uri': 'Invalid uri found', | ||
'string': '\'{}\' should be a string. Check that the value {} has quotes at the start and end. Escape any quotes in the value with \'\\\'', # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoting a non-string makes it look like a string, thus making it harder to see what's wrong… The quote characters should be removed.
One alternative: If the value is a string, first wrap it in double quotes. Then, for the web UI, wrap that value in <code>
tags before performing the string substitution. For other UIs, perhaps wrap that value in backticks instead of single quotes.
This same comment applies to all other similar messages. Quoting a non-integer makes it look like a string, so a user might think they have a string where an integer should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looking at the web UI I see fewer single-quote characters than in these messages.
That said, I notice that string values are not wrapped in double-quotes, which makes them harder to identify as strings – so at least that part of my comment is relevant.
validation_error_template_lookup = { | ||
'date': 'Date is not in the correct format. The correct format is YYYY-MM-DD.', | ||
'date-time': 'Date is not in the correct format. The correct format is YYYY-MM-DDThh:mm:ssZ.', | ||
'uri': 'Invalid uri found', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'URI is not in the correct format.' would be more consistent with the date messages.
Also, some messages (like this one) don't end with a period, while most do. They should all end in period, in case a UI e.g. joins multiple error messages together with spaces.
'string': '\'{}\' should be a string. Check that the value {} has quotes at the start and end. Escape any quotes in the value with \'\\\'', # noqa | ||
'integer': '\'{}\' should be an integer. Check that the value {} doesn’t contain decimal points or any characters other than 0-9. Integer values should not be in quotes. ', # noqa | ||
'number': '\'{}\' should be a number. Check that the value {} doesn’t contain any characters other than 0-9 and dot (\'.\'). Number values should not be in quotes. ', # noqa | ||
'boolean': '\'{}\' should be a JSON boolean, \'true\' or \'false\'.', # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
and false
should not be wrapped in single quotes, which implies a string value. See my other comment for an alternative.
'date': 'Date is not in the correct format. The correct format is YYYY-MM-DD.', | ||
'date-time': 'Date is not in the correct format. The correct format is YYYY-MM-DDT00:00:00Z.', | ||
'uri': 'Invalid uri found', | ||
'string': '<code>{}</code> should be a string. Check that the value {} has quotes at the start and end. Escape any quotes in the value with <code>\</code>', # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second instance of {}
should also have <code>
tags, to avoid ambiguity or confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second {}
is for a clause about nulls:
lib-cove/libcove/lib/common.py
Lines 536 to 549 in 2c35429
null_clause = '' | |
if isinstance(e.validator_value, list): | |
validator_type = e.validator_value[0] | |
if 'null' not in e.validator_value: | |
null_clause = 'is not null, and' | |
else: | |
null_clause = 'is not null, and' | |
message_template = validation_error_template_lookup.get(validator_type, message) | |
message_safe_template = validation_error_template_lookup_safe.get(validator_type) | |
if message_template: | |
message = message_template.format(header, null_clause) | |
if message_safe_template: | |
message_safe = format_html(message_safe_template, header, null_clause) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks – I didn't read the formatting code, just the message templates. A short comment above the message templates about what values are substituted would improve clarity.
Also, please review the UI for ungrammatical sentences and awkward letter casing. This sentence is an example of both:
|
This is a sample file with bad data in it. I've tried to use the value of the bad data to describe why it is bad. The |
Sorry, those urls actually gave the same results, this is fixed now. |
This makes the tests suitable for this PR: OpenDataServices/lib-cove#12 (instead of the larger OpenDataServices/lib-cove#8)
Thanks – but you see how such a file is very confusing in the context of changing wording to "should be" ;) |
Before:
After:
There seems to be either incorrect string substitution or an incorrect message template here. The first message makes sense in that a string value (indicated by double quotes) is empty. If the second message intends to make the subject a field, then the double quotes should be omitted, and ideally fields should be styled differently from values as I mentioned above. Same difference across before and after here, with before:
After:
|
2c35429
to
0a51727
Compare
This reverts commit ad1b06b.
0a51727
to
4a32d4a
Compare
@Bjwebb is this PR still relevant? |
I don't think we have any plans to take this forward. The new messages exist in lib-cove-bods if we want them. |
openownership/cove-bods#16
Return specific validation errors for
oneOf
, by usingstatementType
to pick the correct sub-schema. Only works for BODS.Because the change is BODS specific, tests are currently only in the lib-cove-bods repo - openownership/lib-cove-bods#5
Here's what this looks like in the web interface openownership/cove-bods#16 (comment)