From 2768ecc639f528d6c81a8153a2ce098dfc639f32 Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Mon, 10 Feb 2020 11:51:25 -0500 Subject: [PATCH] remove redundant and repeated traceback and exception output and clarify exceptions --- minetestmapper-numpy.py | 30 +++++++++++++++++++++------- minetestmapper.py | 43 ++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/minetestmapper-numpy.py b/minetestmapper-numpy.py index 430479c..2f4decd 100644 --- a/minetestmapper-numpy.py +++ b/minetestmapper-numpy.py @@ -522,7 +522,9 @@ class LVLDB: return BytesIO(self.conn.Get(pos)) -R_MSG = "" +R_MSG = ("<(The following issue occurred while handling the exception)" + " Could not finish writing r error since r was not" + " initialized>") class World: def __init__(self,args): @@ -857,7 +859,7 @@ class World: mapinfo['undergroundh'][pos] = uhdata.reshape(16,16) break except Exception as e: - print(("Error at ("+str(xpos)+","+str(ypos)+","+str(zpos)+"): "+str(e))) + print(("Error at ("+str(xpos)+","+str(ypos)+","+str(zpos)+"):")) traceback.print_exc() sys.stdout.write("Block data: ") try: @@ -865,15 +867,29 @@ class World: sys.stdout.write("%2.2x "%ord(c)) except NameError: if self.r_error_enable: - print(R_MSG) + sys.stdout.write(R_MSG) # stop here or stdout is several hundred MB: self.r_error_enable = False sys.stdout.write(os.linesep) - sys.stdout.write("Data after node metadata: ") - for c in data_after_node_metadata: - sys.stdout.write("%2.2x "%ord(c)) + sys.stdout.write("Data after node metadata:") + try: + count = 0 + for c in data_after_node_metadata: + sys.stdout.write("%2.2x "%ord(c)) + count += 1 + if count == 0: + sys.stdout.write("<(The following issue occurred while handling the exception) Uh oh, got {}: zero characters to convert to ord>".format(data_after_node_metadata)) + except TypeError: + sys.stdout.write("<(The following issue occurred while handling the" + + " Exception) Uh oh, expected characters in" + " data_after_node_metadata; got:") + sys.stdout.flush() + sys.stdout.write(os.linesep)(type(data_after_node_metadata) + " length " + + str(len(data_after_node_metadata)) + + ":>") sys.stdout.write(os.linesep) - traceback.print_exc() + sys.stdout.write(os.linesep) + exit(1) # stop HUGE stdout self.mapinfo = mapinfo if unknown_node_names: sys.stdout.write("Unknown node names:") diff --git a/minetestmapper.py b/minetestmapper.py index d030065..a3c912e 100644 --- a/minetestmapper.py +++ b/minetestmapper.py @@ -774,24 +774,49 @@ for n in range(len(xlist)): break except Exception as e: print(("Error at (" + str(xpos) + "," + str(ypos) + "," + - str(zpos) + "): " + str(e))) + str(zpos) + "):")) + traceback.print_exc() sys.stdout.write("Block data: ") + last_c = None try: for c in r[0]: + last_c = c sys.stdout.write("%2.2x " % ord(c)) except TypeError: - print("...Uh oh, expected characters in r, got ints" - " (This issue occured while handling the" - " Exception):") + if last_c is not None: + got = "got {}s".format(type(last_c)) + else: + got = "but r was {}".format(type(r)) + try: + got = "but r[0] was {}".format(type(r[0])) + except: + pass + sys.stdout.write("<(The following issue occurred while handling the" + + " Exception)") + sys.stdout.write("...Uh oh, expected characters in r, " + got + + ":>") for c in r[0]: sys.stdout.write("%2.2x " % c) sys.stdout.write(os.linesep) - sys.stdout.write("Data after node metadata: ") - for c in data_after_node_metadata: - sys.stdout.write("%2.2x " % ord(c)) + sys.stdout.write("Data after node metadata:") + try: + count = 0 + for c in data_after_node_metadata: + sys.stdout.write("%2.2x " % ord(c)) + count += 1 + if count == 0: + sys.stdout.write("<(The following issue occurred while handling the exception): uh oh, got {}: zero characters to convert to ord>".format(data_after_node_metadata)) + except TypeError: + sys.stdout.write("<(The following issue occurred while handling the" + + " Exception)...Uh oh, expected characters in" + " data_after_node_metadata; got:") + sys.stdout.flush() + sys.stdout.write(os.linesep)(type(data_after_node_metadata) + " length " + + str(len(data_after_node_metadata)) + + " :>") sys.stdout.write(os.linesep) - traceback.print_exc() - raise e # or std output will be HUGE + sys.stdout.write(os.linesep) + exit(1) # stop HUGE stdout print("Drawing image") # Drawing the picture