Tools/LogAnalyzer: Use more specific exceptions

This commit is contained in:
Luiz Georg 2022-07-11 09:30:25 -03:00 committed by Peter Barker
parent 42f202d0ff
commit da0c365f3d
3 changed files with 8 additions and 8 deletions

View File

@ -40,7 +40,7 @@ class Format(object):
return int(value) return int(value)
elif valueType in "nNZ": elif valueType in "nNZ":
return str(value) return str(value)
except: except ValueError:
pass pass
return value return value
@ -261,7 +261,7 @@ class Channel(object):
if line >= lineNumber: if line >= lineNumber:
return (self.listData[index][1], line) return (self.listData[index][1], line)
index += 1 index += 1
raise Exception("Error finding nearest value for line %d" % lineNumber) raise ValueError("Error finding nearest value for line %d" % lineNumber)
def getNearestValueBack(self, lineNumber): def getNearestValueBack(self, lineNumber):
'''Returns (value,lineNumber)''' '''Returns (value,lineNumber)'''
@ -272,19 +272,19 @@ class Channel(object):
if line <= lineNumber: if line <= lineNumber:
return (self.listData[index][1], line) return (self.listData[index][1], line)
index -= 1 index -= 1
raise Exception("Error finding nearest value for line %d" % lineNumber) raise ValueError("Error finding nearest value for line %d" % lineNumber)
def getNearestValue(self, lineNumber, lookForwards=True): def getNearestValue(self, lineNumber, lookForwards=True):
'''find the nearest data value to the given lineNumber, defaults to first looking forwards. Returns (value,lineNumber)''' '''find the nearest data value to the given lineNumber, defaults to first looking forwards. Returns (value,lineNumber)'''
if lookForwards: if lookForwards:
try: try:
return self.getNearestValueFwd(lineNumber) return self.getNearestValueFwd(lineNumber)
except: except ValueError:
return self.getNearestValueBack(lineNumber) return self.getNearestValueBack(lineNumber)
else: else:
try: try:
return self.getNearestValueBack(lineNumber) return self.getNearestValueBack(lineNumber)
except: except ValueError:
return self.getNearestValueFwd(lineNumber) return self.getNearestValueFwd(lineNumber)
raise Exception("Error finding nearest value for line %d" % lineNumber) raise Exception("Error finding nearest value for line %d" % lineNumber)
@ -797,7 +797,7 @@ class DataflashLog(object):
break break
try: try:
e = typ.from_buffer(data, offset) e = typ.from_buffer(data, offset)
except: except ValueError:
print( print(
"data:{} offset:{} size:{} sizeof:{} sum:{}".format( "data:{} offset:{} size:{} sizeof:{} sum:{}".format(
len(data), offset, typ.SIZE, ctypes.sizeof(typ), offset + typ.SIZE len(data), offset, typ.SIZE, ctypes.sizeof(typ), offset + typ.SIZE

View File

@ -154,7 +154,7 @@ class TestSuite(object):
xml = sys.stdout xml = sys.stdout
else: else:
xml = open(xmlFile, 'w') xml = open(xmlFile, 'w')
except: except IOError:
sys.stderr.write("Error opening output xml file: %s" % xmlFile) sys.stderr.write("Error opening output xml file: %s" % xmlFile)
sys.exit(1) sys.exit(1)

View File

@ -120,7 +120,7 @@ class TestAutotune(Test):
line = logdata.channels['ATUN']['RateMax'].getNearestValueFwd(linenext)[1] line = logdata.channels['ATUN']['RateMax'].getNearestValueFwd(linenext)[1]
if line > a.linestop: if line > a.linestop:
break break
except: except ValueError:
break break
atun = class_from_channel('ATUN')() atun = class_from_channel('ATUN')()
for key in logdata.channels['ATUN']: for key in logdata.channels['ATUN']: