Skip to content

Commit 8bf3aab

Browse files
authored
Merge pull request #638 from FAIRmat-NFDI/599-undescriptive-error-message-cleanup
add a separate error for names with wrong type and remove such keys
2 parents 709ce46 + ae46cc3 commit 8bf3aab

File tree

8 files changed

+374
-110
lines changed

8 files changed

+374
-110
lines changed

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ message:
44
If you use this software, please cite it using the
55
metadata from this file.
66
type: software
7-
version: 0.10.6
7+
version: 0.10.7
88
authors:
99
- given-names: Sherjeel
1010
family-names: Shabih

src/pynxtools/data/NXtest.nxdl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
</group>
4646
<group type="NXdata" name="specified_group" nameType="specified">
4747
<doc>A group with a name and nameType="specified".</doc>
48-
<field name="specified_field" type="NX_FLOAT" units="NX_ANY">
49-
<attribute name="specified_attr_in_field"/>
48+
<field name="specified_field" nameType="specified" type="NX_FLOAT" units="NX_ANY">
49+
<attribute name="specified_attr_in_field" nameType="specified"/>
5050
</field>
5151
<attribute name="specified_attr"/>
5252
</group>

src/pynxtools/dataconverter/convert.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,12 @@ def transfer_data_into_template(
176176
for entry_name in entry_names:
177177
helpers.write_nexus_def_to_entry(data, entry_name, nxdl_name)
178178
if not skip_verify:
179-
valid, keys_to_remove = validate_dict_against(
179+
valid = validate_dict_against(
180180
nxdl_name,
181181
data,
182182
ignore_undocumented=ignore_undocumented,
183183
)
184184

185-
# remove attributes that belong to non-existing fields
186-
187-
for key in keys_to_remove:
188-
# data.__delitem__(key)
189-
del data[key]
190-
191185
if fail and not valid:
192186
raise ValidationFailed(
193187
"The data does not match the given NXDL. "

src/pynxtools/dataconverter/helpers.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import os
2323
import re
2424
from datetime import datetime, timezone
25-
from enum import Enum
25+
from enum import Enum, auto
2626
from functools import lru_cache
2727
from typing import Any, Callable, List, Optional, Tuple, Union, Sequence, cast
2828

@@ -46,30 +46,32 @@
4646

4747

4848
class ValidationProblem(Enum):
49-
UnitWithoutDocumentation = 1
50-
InvalidEnum = 2
51-
OpenEnumWithNewItem = 3
52-
MissingRequiredGroup = 4
53-
MissingRequiredField = 5
54-
MissingRequiredAttribute = 6
55-
InvalidType = 7
56-
InvalidDatetime = 8
57-
IsNotPosInt = 9
58-
ExpectedGroup = 10
59-
MissingDocumentation = 11
60-
MissingUnit = 12
61-
ChoiceValidationError = 13
62-
UnitWithoutField = 14
63-
AttributeForNonExistingField = 15
64-
BrokenLink = 16
65-
FailedNamefitting = 17
66-
NXdataMissingSignalData = 18
67-
NXdataMissingAxisData = 19
68-
NXdataAxisMismatch = 20
69-
KeyToBeRemoved = 21
70-
InvalidConceptForNonVariadic = 22
71-
ReservedSuffixWithoutField = 23
72-
ReservedPrefixInWrongContext = 24
49+
UnitWithoutDocumentation = auto()
50+
InvalidEnum = auto()
51+
OpenEnumWithNewItem = auto()
52+
MissingRequiredGroup = auto()
53+
MissingRequiredField = auto()
54+
MissingRequiredAttribute = auto()
55+
InvalidType = auto()
56+
InvalidDatetime = auto()
57+
IsNotPosInt = auto()
58+
ExpectedGroup = auto()
59+
ExpectedField = auto()
60+
MissingDocumentation = auto()
61+
MissingUnit = auto()
62+
ChoiceValidationError = auto()
63+
UnitWithoutField = auto()
64+
AttributeForNonExistingField = auto()
65+
BrokenLink = auto()
66+
FailedNamefitting = auto()
67+
NXdataMissingSignalData = auto()
68+
NXdataMissingAxisData = auto()
69+
NXdataAxisMismatch = auto()
70+
KeyToBeRemoved = auto()
71+
InvalidConceptForNonVariadic = auto()
72+
ReservedSuffixWithoutField = auto()
73+
ReservedPrefixInWrongContext = auto()
74+
InvalidNexusTypeForNamedConcept = auto()
7375

7476

7577
class Collector:
@@ -96,9 +98,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
9698
f"The value at {path} does not match with the enumerated items from the open enumeration: {value}."
9799
)
98100
elif log_type == ValidationProblem.MissingRequiredGroup:
99-
logger.warning(f"The required group, {path}, hasn't been supplied.")
101+
logger.error(f"The required group, {path}, hasn't been supplied.")
100102
elif log_type == ValidationProblem.MissingRequiredField:
101-
logger.warning(
103+
logger.error(
102104
f"The data entry corresponding to {path} is required "
103105
"and hasn't been supplied by the reader.",
104106
)
@@ -118,9 +120,9 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
118120
f"The value at {path} should be a positive int, but is {value}."
119121
)
120122
elif log_type == ValidationProblem.ExpectedGroup:
121-
logger.warning(
122-
f"Expected a group at {path} but found a field or attribute."
123-
)
123+
logger.error(f"Expected a group at {path} but found a field or attribute.")
124+
elif log_type == ValidationProblem.ExpectedField:
125+
logger.error(f"Expected a field at {path} but found a group.")
124126
elif log_type == ValidationProblem.MissingDocumentation:
125127
if "@" in path.rsplit("/")[-1]:
126128
logger.warning(f"Attribute {path} written without documentation.")
@@ -140,7 +142,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
140142
"but the field does not exist."
141143
)
142144
elif log_type == ValidationProblem.BrokenLink:
143-
logger.warning(f"Broken link at {path} to {value}")
145+
logger.warning(f"Broken link at {path} to {value}.")
144146
elif log_type == ValidationProblem.FailedNamefitting:
145147
logger.warning(f"Found no namefit of {path} in {value}.")
146148
elif log_type == ValidationProblem.NXdataMissingSignalData:
@@ -152,7 +154,7 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
152154
f"Length of axis {path} does not match to {value} in dimension {args[0]}"
153155
)
154156
elif log_type == ValidationProblem.KeyToBeRemoved:
155-
logger.warning(f"The attribute {path} will not be written.")
157+
logger.warning(f"The {value} {path} will not be written.")
156158
elif log_type == ValidationProblem.InvalidConceptForNonVariadic:
157159
value = cast(Any, value)
158160
log_text = f"Given {value.type} name '{path}' conflicts with the non-variadic name '{value}'"
@@ -169,6 +171,12 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
169171
if value != "<unknown>":
170172
log_text += f" It is only valid in the context of {value}."
171173
logger.error(log_text)
174+
elif log_type == ValidationProblem.InvalidNexusTypeForNamedConcept:
175+
value = cast(Any, value)
176+
logger.error(
177+
f"The type ('{args[0] if args else '<unknown>'}') of the given concept '{path}' "
178+
f"conflicts with another existing concept of the same name, which is of type '{value.type}'."
179+
)
172180

173181
def collect_and_log(
174182
self,

0 commit comments

Comments
 (0)