Skip to content

Commit d4581df

Browse files
committed
Improve error when parsing invalid wsdl's
1 parent aa2ba63 commit d4581df

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Diff for: src/zeep/exceptions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class TransportError(Error):
3939

4040

4141
class LookupError(Error):
42-
pass
42+
def __init__(self, *args, **kwargs):
43+
self.qname = kwargs.pop('qname', None)
44+
self.item_name = kwargs.pop('item_name', None)
45+
self.location = kwargs.pop('location', None)
46+
super(LookupError, self).__init__(*args, **kwargs)
4347

4448

4549
class NamespaceError(Error):

Diff for: src/zeep/xsd/schema.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,23 @@ def resolve(self):
374374
schema.resolve()
375375

376376
def _resolve_dict(val):
377-
for key, obj in val.items():
378-
new = obj.resolve()
379-
assert new is not None, "resolve() should return an object"
380-
val[key] = new
377+
try:
378+
for key, obj in val.items():
379+
new = obj.resolve()
380+
assert new is not None, "resolve() should return an object"
381+
val[key] = new
382+
except exceptions.LookupError as exc:
383+
raise exceptions.LookupError(
384+
(
385+
"Unable to resolve %(item_name)s %(qname)s in "
386+
"%(file)s. (via %(parent)s)"
387+
) % {
388+
'item_name': exc.item_name,
389+
'item_name': exc.item_name,
390+
'qname': exc.qname,
391+
'file': exc.location,
392+
'parent': obj.qname,
393+
})
381394

382395
_resolve_dict(self._attribute_groups)
383396
_resolve_dict(self._attributes)
@@ -473,10 +486,13 @@ def _get_instance(self, qname, items, item_name):
473486
raise exceptions.LookupError((
474487
"No %(item_name)s '%(localname)s' in namespace %(namespace)s. " +
475488
"Available %(item_name_plural)s are: %(known_items)s"
476-
) % {
477-
'item_name': item_name,
478-
'item_name_plural': item_name + 's',
479-
'localname': qname.localname,
480-
'namespace': qname.namespace,
481-
'known_items': known_items or ' - '
482-
})
489+
) % {
490+
'item_name': item_name,
491+
'item_name_plural': item_name + 's',
492+
'localname': qname.localname,
493+
'namespace': qname.namespace,
494+
'known_items': known_items or ' - '
495+
},
496+
qname=qname,
497+
item_name=item_name,
498+
location=self._location)

0 commit comments

Comments
 (0)