nexusformat / definitions

Definitions of the NeXus Standard File Structure and Contents
https://manual.nexusformat.org/
Other
26 stars 55 forks source link

NXDL parsing exceptions missing necessary details #1266

Closed prjemian closed 1 year ago

prjemian commented 1 year ago

Exceptions reported in CI do not indicate which NXDL file and line triggered each problem.

see: https://pipelines.actions.githubusercontent.com/serviceHosts/450b0598-1549-4d8a-b222-20c2cf327859/_apis/pipelines/1/runs/1080/signedlogcontent/2?urlExpires=2023-05-30T14%3A28%3A13.6751717Z&urlSigningMethod=HMACV1&urlSignature=QKq4zK3g8YPqFSGqqIhmHBWHqZUoV40VjIN%2B1daA7VU%3D

Originally posted by @prjemian in https://github.com/nexusformat/definitions/issues/1265#issuecomment-1568534464

woutdenolf commented 1 year ago

https://github.com/nexusformat/definitions/actions/runs/5122807646/jobs/9212410397

File and line are displayed in the traceaback:

 lxml.etree.DocumentInvalid: Element '{http://definition.nexusformat.org/nxdl/3.1}dimensions': 
    This element is not expected. Expected is one of 
    ( {http://definition.nexusformat.org/nxdl/3.1}attribute, 
    {http://definition.nexusformat.org/nxdl/3.1}enumeration )., line 200

During handling of the above exception, another exception occurred:

definitions.dev_tools.globals.errors.NXDLSyntaxError: 
     /home/runner/work/definitions/definitions/contributed_definitions/NXfiber.nxdl.xml

This chained exception comes from

try:
       xml_schema.assertValid(xml_tree)
except lxml.etree.DocumentInvalid:
       raise errors.NXDLSyntaxError(xml_file_name)

We can improve the error message to include everything in a single error message instead looking down the chain.