Add error handling to stage-manager
PATCH 1/1 Add error handling to stage-manager
Add an error message telling the cause of the crash to the user.
--- recipes/stage-manager/files/stage-manager | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-)
recipes/stage-manager/files/stage-manager +9 -5
@@ -29,11 +29,15 @@ def read_cache(cachefile): lines = f.readlines() f.close() for l in lines: - data = l.split('|') - cache[data[0]] = {} - cache[data[0]]['ts'] = int(data[1]) - cache[data[0]]['size'] = int(data[2]) - cache[data[0]]['seen'] = False + try: + data = l.split('|') + cache[data[0]] = {} + cache[data[0]]['ts'] = int(data[1]) + cache[data[0]]['size'] = int(data[2]) + cache[data[0]]['seen'] = False + except IndexError, e: + print("Corrupted line in cachefile " + cachefile + " : " + l) + raise e return cache def mkdirhier(dir):
Signature · 1 line
1.6.3.3
Am 23.04.2010 um 14:42 schrieb Mickaël Chazaux:
Quoted 19 lines
Add an error message telling the cause of the crash to the user.
---
recipes/stage-manager/files/stage-manager | 14 +++++++++-----1 files changed, 9 insertions(+), 5 deletions(-)recipes/stage-manager/files/stage-manager +1
-5@@ -29,11 +29,15 @@ def read_cache(cachefile): lines = f.readlines() f.close() for l in lines: - data = l.split('|') - cache[data[0]] = {} - cache[data[0]]['ts'] = int(data[1]) - cache[data[0]]['size'] = int(data[2]) - cache[data[0]]['seen'] = False + try:
recipes/stage-manager/files/stage-manager def read_cache(cachefile): · line 42
Quoted 10 lines
recipes/stage-manager/files/stage-manager +8
-0+ data = l.split('|') + cache[data[0]] = {} + cache[data[0]]['ts'] = int(data[1]) + cache[data[0]]['size'] = int(data[2]) + cache[data[0]]['seen'] = False + except IndexError, e: + print("Corrupted line in cachefile " + cachefile + " : " + l) + raise e return cache
Completely unrelated, but this code is slow. The recurring evaluation of cache[data[0]] is not being cached or optimized, I suggest something along:
d = cache[data[0]] = {}
d["ts"] = int(data[1])
d["size"] = int(data[2])
...
:M: