Skip to content

Commit 4c8e485

Browse files
committed
Provide more details in data validation messages
1 parent 95561c1 commit 4c8e485

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2525

2626
### Fixed
2727

28+
- Provide more details in data validation messages
2829
- Fix issue with `get_pyarrow_type_for_geopandas`
2930

3031
## [v0.3.2] - 2024-04-12

fiboa_cli/validate_data.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,38 @@ def validate_column(data, rules):
2828
def validate_string(value, rules):
2929
issues = []
3030
if 'minLength' in rules and len(value) < rules['minLength']:
31-
issues.append(f"String is shorter than the minimum length of {rules['minLength']}.")
31+
issues.append(f"String '{value}' is shorter than the minimum length of {rules['minLength']}.")
3232
if 'maxLength' in rules and len(value) > rules['maxLength']:
33-
issues.append(f"String is longer than the maximum length of {rules['maxLength']}.")
33+
issues.append(f"String '{value}' is longer than the maximum length of {rules['maxLength']}.")
3434
if 'pattern' in rules and not re.match(rules['pattern'], value):
35-
issues.append(f"String does not match the required pattern: {rules['pattern']}.")
35+
issues.append(f"String '{value}' does not match the required pattern: {rules['pattern']}.")
3636
if 'enum' in rules and value not in rules['enum']:
37-
issues.append(f"String is not one of the permitted values in the enumeration.")
37+
allowed = ", ".join(rules['enum'])
38+
issues.append(f"String '{value}' is not one of the allowed values in the enumeration: {allowed}")
3839
if 'format' in rules:
3940
# todo: pre-compile regexes
4041
if rules['format'] == 'email' and not re.match(r"[^@]+@[^@]+\.[^@]+", value):
41-
issues.append("String is not a valid email.")
42+
issues.append(f"String '{value}' is not a valid email address.")
4243
if rules['format'] == 'uri' and not urlparse(value).scheme:
43-
issues.append("String is not a valid URI.")
44+
issues.append(f"String '{value}' is not a valid URI.")
4445
if rules['format'] == 'uuid' and not re.match(r"^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\Z", value):
45-
issues.append("String is not a valid UUID.")
46+
issues.append(f"String '{value}' is not a valid UUID.")
4647
return issues
4748

4849
# Numerical validation
4950
def validate_numerical(value, rules):
5051
issues = []
5152
if 'minimum' in rules and value < rules['minimum']:
52-
issues.append(f"Value is less than the minimum allowed value of {rules['minimum']}.")
53+
issues.append(f"Value {value} is less than the minimum allowed value of {rules['minimum']}.")
5354
if 'maximum' in rules and value > rules['maximum']:
54-
issues.append(f"Value is greater than the maximum allowed value of {rules['maximum']}.")
55+
issues.append(f"Value {value} is greater than the maximum allowed value of {rules['maximum']}.")
5556
if 'exclusiveMinimum' in rules and value <= rules['exclusiveMinimum']:
56-
issues.append(f"Value is less than or equal to the exclusive minimum value of {rules['exclusiveMinimum']}.")
57+
issues.append(f"Value {value} is less than or equal to the exclusive minimum value of {rules['exclusiveMinimum']}.")
5758
if 'exclusiveMaximum' in rules and value >= rules['exclusiveMaximum']:
58-
issues.append(f"Value is greater than or equal to the exclusive maximum value of {rules['exclusiveMaximum']}.")
59+
issues.append(f"Value {value} is greater than or equal to the exclusive maximum value of {rules['exclusiveMaximum']}.")
5960
if 'enum' in rules and value not in rules['enum']:
60-
issues.append("Value is not one of the permitted values in the enumeration.")
61+
allowed = ", ".join(map(str, rules['enum']))
62+
issues.append(f"String '{value}' is not one of the allowed values in the enumeration: {allowed}")
6163
return issues
6264

6365
# Array validation

0 commit comments

Comments
 (0)