identifiers: Make invalid persistent identifier parsing raise error
So far we accept any kinds of persistent identifier, including invalid ones. We should raise instead.
Related #1104 (closed)
Before, for example:
$ python3
In [1]: from swh.model.identifiers import parse_persistent_identifier
In [2]: parse_persistent_identifier('foo')
Out[2]: {'namespace': 'foo', 'scheme_version': {}}
Now:
$ python3
Python 3.6.6rc1 (default, Jun 13 2018, 06:59:48)
[GCC 8.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from swh.model.identifiers import parse_persistent_identifier
>>> parse_persistent_identifier('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tony/work/inria/repo/swh/swh-environment/swh-model/swh/model/identifiers.py", line 677, in parse_persistent_identifier
'Wrong format: There should be 4 mandatory parameters')
swh.model.identifiers.SWHMalformedIdentifierException: Wrong format: There should be 4 mandatory parameters
Test Plan
Tests should still pass
Migrated from D346 (view on Phabricator)
Merge request reports
Activity
As per discussion with anlambert, converge towards the existing swh-web utils code [1]
-
[1] https://forge.softwareheritage.org/source/swh-web/browse/master/swh/web/common/utils.py$254
-
identifiers: Also validate the hash is correct
-
identifiers: Fix wrong type in docstring
-
As per discussion with anlambert, converge towards the existing swh-web utils code [1]
Clarifying, the webapp's utils code is a 'duplicate' that will possibly become an adapter of the api here. Probably delegating the parsing to the swh.model function, and possibly transforming any exceptions raised during parsing into the needed swh.web ones. So that, everything continues working as expected in the swh.web module.
mentioned in merge request swh-web!52 (closed)
mentioned in commit bd22f277