Skip to content

UM file opening: error message is unfriendly if "um" arg to "cf.read" is missing required keys #306

@alaniwi

Description

@alaniwi

In cf-python==3.11.0

Example:

Actual behaviour (paths munged):

>>> f1 = cf.read("packed.pp", um={"fmt": "pp", "endian":"big", "word_size": "4", "version": "4.2"})  # this is okay
>>> f2 = cf.read("packed.pp", um={"fmt": "pp", "endian":"big", "word_size": "4"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/lib/python3.8/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
  File "/path/to/lib/python3.8/site-packages/cf/read_write/read.py", line 757, in read
    file_contents = _read_a_file(
  File "/path/to/lib/python3.8/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
  File "/path/to/lib/python3.8/site-packages/cf/read_write/read.py", line 1031, in _read_a_file
    out = UM.read(
  File "/path/to/lib/python3.8/site-packages/cfdm/decorators.py", line 171, in verbose_override_wrapper
    return method_with_verbose_kwarg(*args, **kwargs)
  File "/path/to/lib/python3.8/site-packages/cf/read_write/um/umread.py", line 3501, in read
    um = [
  File "/path/to/lib/python3.8/site-packages/cf/read_write/um/umread.py", line 3502, in <listcomp>
    UMField(
  File "/path/to/lib/python3.8/site-packages/cf/read_write/um/umread.py", line 668, in __init__
    if header_um_version > 0 and int(um_version) == um_version:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Desired behaviour. something like:

>>> f2 = cf.read("packed.pp", um={"fmt": "pp", "endian":"big", "word_size": "4"})
Traceback (most recent call last):
[...]
KeyError: dictionary used as optional 'um' parameter must contain keys 'fmt', 'endian', 'word_size' and 'version'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingum/ppRelating to UM or PP format files

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions