2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-29 05:11:52 +00:00

more correct error message

This commit is contained in:
Philip Sargent 2023-08-04 16:08:07 +03:00
parent 3b9a2b990d
commit c8430d1ff7

View File

@ -310,13 +310,13 @@ def getXML(text, itemname, minItems=1, maxItems=None, context=""):
Should throw exception rather than producing error message here, Should throw exception rather than producing error message here,
then handle exception in calling routine where it has the context. then handle exception in calling routine where it has the context.
This always succeeds, but it produices error message on the terminal and in the This always succeeds, but it produces error message on the terminal and in the
DatIssues log. DataIssues log.
""" """
items = re.findall("<%(itemname)s>(.*?)</%(itemname)s>" % {"itemname": itemname}, text, re.S) items = re.findall("<%(itemname)s>(.*?)</%(itemname)s>" % {"itemname": itemname}, text, re.S)
if len(items) < minItems: if len(items) < minItems:
message = ( message = (
" ! %(count)i x %(itemname)s found, at least %(min)i expected. Load ABORT. " " ! %(count)i x %(itemname)s found, at least %(min)i expected. Load may ABORT. "
% {"count": len(items), "itemname": itemname, "min": minItems} % {"count": len(items), "itemname": itemname, "min": minItems}
+ " in file " + " in file "
+ context + context
@ -326,7 +326,7 @@ def getXML(text, itemname, minItems=1, maxItems=None, context=""):
if maxItems is not None and len(items) > maxItems: if maxItems is not None and len(items) > maxItems:
message = ( message = (
" ! %(count)i x %(itemname)s found, no more than %(max)i expected in this XML unit. Load ABORT. " " ! %(count)i x %(itemname)s found, no more than %(max)i expected in this XML unit. Load may ABORT. "
% {"count": len(items), "itemname": itemname, "max": maxItems} % {"count": len(items), "itemname": itemname, "max": maxItems}
+ " in file " + " in file "
+ context + context