Skip to content

Handle malformed NXDL files without raising exceptions - #272

Merged
rayosborn merged 1 commit into
nexpy:mainfrom
rayosborn:harden-nxdl-validation
Oct 2, 2026
Merged

rayosborn merged 1 commit into
nexpy:mainfrom
rayosborn:harden-nxdl-validation

Conversation

@rayosborn

Copy link
Copy Markdown
Contributor

Summary

Malformed or unusual NXDL files now produce logged errors from nxcheck,
nxvalidate and validate_application() instead of Python tracebacks, and a
few related validation bugs are fixed.

Robustness against malformed NXDL

  • parse_nxdl(): XML syntax errors, unreadable files and a wrong root tag
    raise NeXusError.
  • extends: a missing parent, a circular chain or a self-reference raises
    NeXusError, for both base classes and application definitions. A missing
    extends attribute or <group> element in an application is also handled.
  • Unnamed <field>, <group>, <link> and <attribute> elements are
    skipped and reported as errors.
  • xml_to_dict() skips enumeration items without a value and <dim>
    elements with a non-integer index.
  • A non-integer minOccurs is ignored, as maxOccurs already was.
  • lint_nxdl() reports a broken nxdl.xsd as a warning.
  • GroupValidator initialises ignoreExtra* for unknown classes, and
    Validator.__repr__ tolerates a missing file path.

Data-side guards

  • check_data no longer fails when @axes is longer than the signal rank
    or an axis is scalar or a group.
  • check_enumeration handles array-valued fields.
  • A <field> or <link> in an application definition that matches a group
    in the file is reported as an error.
  • Validating from a path whose top-level group has no base class no longer
    raises AttributeError.

Other fixes

  • The size of the last dimension is now checked correctly in
    check_dimensions.
  • ignoreExtraFields="false" (and the other ignoreExtra* attributes) is no
    longer treated as true.
  • Symbol-consistency messages are now output during application validation.
  • Removed the unused Validator.get_attributes and fixed a "TThe" typo.

New tests cover each malformed-NXDL case. nxcheck and nxvalidate run
without exceptions on all files in the NeXus example data.

🤖 Generated with Claude Code

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>
@rayosborn
rayosborn merged commit 603a6ee into nexpy:main Oct 2, 2026
16 checks passed
@rayosborn
rayosborn deleted the harden-nxdl-validation branch October 2, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant