[wmlunits] Fix error logging.

Now that a separate process is doing the WML parsing, need to serialize exceptions in the other process and send them to the main process to access them there.
This commit is contained in:
Elias Pschernig 2013-05-25 10:26:09 +02:00
parent ab072b4960
commit 6632eaae33
3 changed files with 25 additions and 15 deletions

View file

@ -106,6 +106,8 @@ def main(folder):
error_kind = "wml error"
elif "<PARSE ERROR>" in text:
error_kind = "parse error"
elif "<TIMEOUT ERROR>" in text:
error_kind = "timeout"
source = []
@ -144,9 +146,9 @@ def main(folder):
lines_count = 0
for line in text.splitlines():
line = line.strip()
if line in ["<INTERNAL ERROR>", "<WML ERROR>", "<PARSE ERROR>"]:
if line in ["<INTERNAL ERROR>", "<WML ERROR>", "<PARSE ERROR>", "<TIMEOUT ERROR>"]:
htmlerr.write("<p>")
elif line in ["</INTERNAL ERROR>", "</WML ERROR>", "</PARSE ERROR>"]:
elif line in ["</INTERNAL ERROR>", "</WML ERROR>", "</PARSE ERROR>", "</TIMEOUT ERROR>"]:
htmlerr.write("</p>")
else:
err_html = postprocess(line)

View file

@ -21,11 +21,12 @@ class WMLError(Exception):
Catch this exception to retrieve the first error message from
the parser.
"""
def __init__(self, parser, message):
self.line = parser.parser_line
self.wml_line = parser.last_wml_line
self.message = message
self.preprocessed = parser.preprocessed
def __init__(self, parser = None, message = None):
if parser:
self.line = parser.parser_line
self.wml_line = parser.last_wml_line
self.message = message
self.preprocessed = parser.preprocessed
def __str__(self):
r = "WMLError:\n"

View file

@ -21,6 +21,8 @@ import unit_tree.html_output as html_output
import unit_tree.overview
import unit_tree.wiki_output as wiki_output
TIMEOUT = 5
def copy_images():
print("Recolorizing pictures.")
image_collector.copy_and_color_images(options.output)
@ -130,19 +132,24 @@ def list_contents():
options.data_dir,
options.transdir)
#print("remote", local.wesnoth)
local.wesnoth.parser.parse_text(wml, defines)
q.put(local.wesnoth)
try:
local.wesnoth.parser.parse_text(wml, defines)
q.put(("ok", local.wesnoth))
except Exception as e:
q.put(("e", e))
q = multiprocessing.Queue()
p = multiprocessing.Process(target = f, args = (options, wml, defines, q))
p.start()
try:
local.wesnoth = q.get(timeout = 5)
s, local.wesnoth = q.get(timeout = TIMEOUT)
except Queue.Empty:
p.terminate()
raise
#print("local", local.wesnoth)
#print("local", s, local.wesnoth)
p.join()
if s == "e":
raise local.wesnoth
def get_version(addon):
try:
@ -222,9 +229,9 @@ def list_contents():
sys.stdout.write("failed\n")
except Queue.Empty as e:
ef = open(logname, "w")
ef.write("<PARSE ERROR>\n")
ef.write(str(e))
ef.write("</PARSE ERROR>\n")
ef.write("<TIMEOUT ERROR>\n")
ef.write("Failed to parse the WML within " + str(TIMEOUT) + " seconds.")
ef.write("</TIMEOUT ERROR>\n")
ef.close()
sys.stdout.write("failed\n")
finally: