Skip to content

extract_npm_package_author: Handle list of dict authors layout

Some package.json files may contain an authors field consisting in a list of dict. So handle that case to avoid errors such as:

[2019-04-11 12:03:21,650: ERROR/ForkPoolWorker-19] Loading failure, updating to `partial` status
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/swh/loader/core/loader.py", line 893, in load
    more_data_to_fetch = self.fetch_data()
  File "/usr/lib/python3/dist-packages/swh/loader/npm/loader.py", line 203, in fetch_data
    data = next(self.new_versions)
  File "/usr/lib/python3/dist-packages/swh/loader/npm/client.py", line 145, in prepare_package_versions
    version_data)
  File "/usr/lib/python3/dist-packages/swh/loader/npm/client.py", line 200, in _prepare_package_version
    author = extract_npm_package_author(package_json)
  File "/usr/lib/python3/dist-packages/swh/loader/npm/utils.py", line 92, in extract_npm_package_author
    author_data = parse_npm_package_author(package_json['authors'][0])
  File "/usr/lib/python3/dist-packages/swh/loader/npm/utils.py", line 52, in parse_npm_package_author
    author_str.replace('<>', '').replace('()', ''),
AttributeError: 'dict' object has no attribute 'replace'

Related T1644


Migrated from D1408 (view on Phabricator)

Merge request reports