EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit f267ca1a authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Improved error handling in XML parsing

parent ab41b313
No related branches found
No related tags found
3 merge requests!36Staging to master to prepare 1.0.0 release,!32Registrar modularization,!27Registrar modularization
......@@ -8,6 +8,7 @@ import logging
import lxml.etree
from .source import Source
from .exceptions import RegistrationError
logger = logging.getLogger(__name__)
......@@ -29,6 +30,9 @@ class Parameter:
namespaces: dict = field(default_factory=dict)
class ParserError(RegistrationError):
pass
def parse_metadata_schema(tree: lxml.etree._ElementTree, schema: dict, namespaces: dict=None) -> dict:
out = {}
for key, param in schema.items():
......@@ -39,7 +43,10 @@ def parse_metadata_schema(tree: lxml.etree._ElementTree, schema: dict, namespace
for v in values
]
else:
value = param.parser(values[0]) if param.parser else values[0]
try:
value = param.parser(values[0]) if param.parser else values[0]
except IndexError:
raise ParserError(f'Failed to fetch single value for parameter {key}')
out[key] = value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment