Skip to content

Commit

Permalink
remove fancy error texts
Browse files Browse the repository at this point in the history
  • Loading branch information
briehl committed Dec 11, 2024
1 parent 748380c commit 528bb40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
24 changes: 12 additions & 12 deletions import_specifications/schema/dts_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"instructions": {
"type": "object",
"properties": {
"protocol": {"type": "string"},
"protocol": {
"type": "string",
"const": "KBase narrative import"
},
"objects": {
"type": "array",
"items": {
Expand All @@ -15,17 +18,14 @@
"data_type": {"type": "string"},
"parameters": {
"type": "object",
"patternProperties": {
".*": {
"oneOf": [
{"type": "string"},
{"type": "number"},
{"type": "boolean"},
{"type": "null"}
]
}
},
"additionalProperties": false
"additionalProperties": {
"oneOf": [
{"type": "string"},
{"type": "number"},
{"type": "boolean"},
{"type": "null"}
]
}
}
},
"required": ["data_type", "parameters"]
Expand Down
17 changes: 2 additions & 15 deletions staging_service/import_specifications/individual_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,22 +359,9 @@ def parse_dts_manifest(path: Path, dts_manifest_schema: dict) -> ParseResults:
validator = jsonschema.Draft202012Validator(dts_manifest_schema)
for err in validator.iter_errors(manifest_json):
err_str = err.message
err_path = err.absolute_path
err_path = list(err.absolute_path)
if err_path:
# paths can look like, say, ["instructions", "objects", 0, "data_type"]
# convert that '0' to "item 0" to be slightly more readable to users.
# kind of a mouthful below, but does that conversion in place
# The error above gets translated into:
# "<err.message> at instructions/objects/item 0/data_type"
#
# Another example would be if the path is just ["instructions"] and it's missing
# a property, the error might be:
# "missing property 'foo' for 'instructions'"
err_path = [f"item {elem}" if isinstance(elem, int) else elem for elem in err_path]
prep = "for"
if len(err_path) > 1:
prep = "at"
err_str += f" {prep} {'/'.join(err_path)}"
err_str += f" at {err_path}"
errors.append(Error(ErrorType.PARSE_FAIL, err_str, spcsrc))
except jsonschema.exceptions.SchemaError:
return _error(Error(ErrorType.OTHER, "Manifest schema is invalid", spcsrc))
Expand Down
2 changes: 1 addition & 1 deletion tests/import_specifications/test_individual_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ def test_dts_manifest_fail_with_path(
[
Error(
ErrorType.PARSE_FAIL,
"'data_type' is a required property at instructions/objects/item 1",
"'data_type' is a required property at ['instructions', 'objects', 1]",
SpecificationSource(manifest_path),
)
],
Expand Down

0 comments on commit 528bb40

Please sign in to comment.