Skip to content
Snippets Groups Projects
Commit baf85301 authored by Daniel Brown's avatar Daniel Brown
Browse files

more error handling

parent c01cd0ad
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,6 @@ class FinesseRunError(BasePyKatException) : ...@@ -50,6 +50,6 @@ class FinesseRunError(BasePyKatException) :
self.__err = err self.__err = err
self.__kat = kat self.__kat = kat
BasePyKatException.__init__(self, "Finesse error (file {1}):\n{0}".format(self.__err, self.__kat)) BasePyKatException.__init__(self, self.__err)
#BasePyKatException.__init__(self, "{0}".format(self.__err)) #BasePyKatException.__init__(self, "{0}".format(self.__err))
...@@ -554,6 +554,8 @@ class kat(object): ...@@ -554,6 +554,8 @@ class kat(object):
Before fully parsing a bunch of commands firstly any constants or variables Before fully parsing a bunch of commands firstly any constants or variables
to be recorded and replaced. to be recorded and replaced.
""" """
try:
constants = self.constants constants = self.constants
for line in commands: for line in commands:
...@@ -602,6 +604,10 @@ class kat(object): ...@@ -602,6 +604,10 @@ class kat(object):
return commands_new return commands_new
except pkex.BasePyKatException as ex:
pkex.PrintError("Error processing constants:", ex)
sys.exit(1)
def parseCommands(self, commands, blocks=None): def parseCommands(self, commands, blocks=None):
try: try:
blockComment = False blockComment = False
...@@ -1007,6 +1013,7 @@ class kat(object): ...@@ -1007,6 +1013,7 @@ class kat(object):
line = unicode(aline, "utf-8") line = unicode(aline, "utf-8")
else: else:
line = aline line = aline
if len(line) > 0: if len(line) > 0:
# remove any ANSI commands # remove any ANSI commands
#ansi = re.compile(r'\x1b[^m]*m') #ansi = re.compile(r'\x1b[^m]*m')
...@@ -1026,12 +1033,14 @@ class kat(object): ...@@ -1026,12 +1033,14 @@ class kat(object):
sys.stdout.write("\r{0} {1}".format(action, prc)) sys.stdout.write("\r{0} {1}".format(action, prc))
else: else:
sys.stdout.write("\r{0} {1}".format(str(action, 'utf-8'), str(prc, 'utf-8'))) sys.stdout.write("\r{0} {1}".format(str(action, 'utf-8'), str(prc, 'utf-8')))
elif line.lstrip().startswith(b'*'): elif line.lstrip().startswith(b'*'):
if self.verbose: if self.verbose:
if six.PY2: if six.PY2:
sys.stdout.write(line) sys.stdout.write(line)
else: else:
sys.stdout.write(str(line,'utf-8')) sys.stdout.write(str(line,'utf-8'))
elif line.rstrip().endswith(b'%'): elif line.rstrip().endswith(b'%'):
vals = line.split("-") vals = line.split("-")
action = vals[0].strip() action = vals[0].strip()
...@@ -1066,8 +1075,7 @@ class kat(object): ...@@ -1066,8 +1075,7 @@ class kat(object):
# If Finesse returned an error, just print that and exit! # If Finesse returned an error, just print that and exit!
if p.returncode != 0: if p.returncode != 0:
print (err) raise pkex.FinesseRunError(err, katfile.name)
sys.exit(1)
self.__prevrunfilename = katfile.name self.__prevrunfilename = katfile.name
...@@ -1140,8 +1148,10 @@ class kat(object): ...@@ -1140,8 +1148,10 @@ class kat(object):
else: else:
return r return r
except pkex.FinesseRunError as fe: except pkex.FinesseRunError as ex:
print (fe) pkex.PrintError("Error from Finesse:", ex)
except pkex.BasePyKatException as ex:
pkex.PrintError("Error from pykat:", ex)
finally: finally:
if self.verbose: print ("") if self.verbose: print ("")
if self.verbose: print ("Finished in " + str(datetime.datetime.now()-start)) if self.verbose: print ("Finished in " + str(datetime.datetime.now()-start))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment