Handle malformed NXDL files without raising exceptions - #272
Merged
Merged
Conversation
Parse errors, bad or circular "extends" chains, missing <group> elements, unnamed elements, malformed enumeration/dim entries and non-integer minOccurs values now produce logged NeXusErrors or errors instead of tracebacks. Also guards several data-side crashes in check_data, check_enumeration and ApplicationValidator.validate_group, fixes an off-by-one in the dimension size check, reads ignoreExtra* values rather than mere presence, and outputs symbol-consistency messages during application validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Malformed or unusual NXDL files now produce logged errors from
nxcheck,nxvalidateandvalidate_application()instead of Python tracebacks, and afew related validation bugs are fixed.
Robustness against malformed NXDL
parse_nxdl(): XML syntax errors, unreadable files and a wrong root tagraise
NeXusError.extends: a missing parent, a circular chain or a self-reference raisesNeXusError, for both base classes and application definitions. A missingextendsattribute or<group>element in an application is also handled.<field>,<group>,<link>and<attribute>elements areskipped and reported as errors.
xml_to_dict()skips enumeration items without avalueand<dim>elements with a non-integer
index.minOccursis ignored, asmaxOccursalready was.lint_nxdl()reports a brokennxdl.xsdas a warning.GroupValidatorinitialisesignoreExtra*for unknown classes, andValidator.__repr__tolerates a missing file path.Data-side guards
check_datano longer fails when@axesis longer than the signal rankor an axis is scalar or a group.
check_enumerationhandles array-valued fields.<field>or<link>in an application definition that matches a groupin the file is reported as an error.
raises
AttributeError.Other fixes
check_dimensions.ignoreExtraFields="false"(and the otherignoreExtra*attributes) is nolonger treated as true.
Validator.get_attributesand fixed a "TThe" typo.New tests cover each malformed-NXDL case.
nxcheckandnxvalidaterunwithout exceptions on all files in the NeXus example data.
🤖 Generated with Claude Code