Skip to content

nxinspect crashes when cannot resolve the link to an internal field #37

@jkotan

Description

@jkotan

The issue is similar to #12 but for internal links i.e. when a target of internal link is not created
nxinspect crashes e.g.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 4529, in __getitem__
    node = node.entries[name]
           ~~~~~~~~~~~~^^^^^^
KeyError: 'target'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 5270, in __getattr__
    return getattr(self.nxlink, name)
                   ^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 5371, in nxlink
    self._link = self.internal_link
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 5403, in internal_link
    return self.nxroot[self._target]
           ~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 4531, in __getitem__
    raise NeXusError("Invalid path")
nexusformat.nexus.tree.NeXusError: Invalid path

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jkotan/testinst/local/bin/nxinspect", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/scripts/nxinspect.py", line 75, in main
    validate_file(filename, path=path, definitions=definitions)
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/validate.py", line 953, in validate_file
    validator.validate(path)
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/validate.py", line 926, in validate
    validator.validate(item, indent=indent)
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/validate.py", line 576, in validate
    field_validator.validate(tag, item, parent=self, indent=indent)
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/validate.py", line 840, in validate
    self.check_type(field, tag['@type'])
  File "/home/jkotan/testinst/local/lib/python3.11/dist-packages/nxvalidate/validate.py", line 613, in check_type
    if is_valid_float(field.dtype):
                      ^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/nexusformat/nexus/tree.py", line 5272, in __getattr__
    raise NeXusError(f"Cannot resolve the link to '{self._target}'")
nexusformat.nexus.tree.NeXusError: Cannot resolve the link to '/scan/sample_environment/mlz_stressihtf2_v2/He/parameters/target/value'

Instead, it would be nice to print an error, e.g. simialar one to the external links

This is a broken link to "/scan/sample_environment/mlz_stressihtf2_v2/He/parameters/target/value"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions