Skip to content

catch exception on empty yml metadata file and throw useful message

If for any reason there was an empty yml metadata file, one just got a stack trace without a useful hint. Took me a while to figure the reason when it happened first. With this patch, instead of the stack trace like

CRITICAL: Unknown exception found!
Traceback (most recent call last):
  File "…/fdroidserver/fdroid", line 150, in <module>
    main()
  File "…/fd_gitlab/fdroidserver/fdroid", line 126, in main
    mod.main()
  File "…/fdroidserver/fdroidserver/update.py", line 1737, in main
    apps = metadata.read_metadata()
  File "…/fdroidserver/fdroidserver/metadata.py", line 736, in read_metadata
    app = parse_metadata(metadatapath, packageName in check_vcs)
  File "…/fdroidserver/fdroidserver/metadata.py", line 942, in parse_metadata
    parse_yaml_metadata(mf, app)
  File "…/fdroidserver/fdroidserver/metadata.py", line 992, in parse_yaml_metadata
    app.update(yamldata)
TypeError: 'NoneType' object is not iterable

one now gets a more user friendly error which next to the exception message also includes the name of the "corrupted file":

CRITICAL: parse_yaml_metadata: 'NoneType' object is not iterable (metadata file "metadata/foobar.yml" empty?)

Note: This error doesn't occur with .txt or .json metadata, which is why I didn't patch those functions.

Merge request reports