Skip to contentSkip to conversation

Add error handling to read_cache in stage-manager

PATCH In review Mickaël Chazaux 3 participants 4 messages Apr 26, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add error handling to read_cache in stage-manager

Sometimes stage-manager crashes with this message :
Traceback (most recent call last):
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 79, in <module>
cache = read_cache(options.cachefile)
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 34, in read_cache
cache[data[0]]['ts'] = int(data[1])
IndexError: list index out of range

This is due to a corrupted cache file. This patch adds an error message telling the cause of the crash to the user.

---
 recipes/stage-manager/files/stage-manager          |   14 +++++++++-----
 recipes/stage-manager/stagemanager-native_0.0.1.bb |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)
recipes/stage-manager/files/stage-manager +9 -5
index 536d1af..93196ff 100755
@@ -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('|')
+            d = cache[data[0]] = {}
+            d['ts'] = int(data[1])
+            d['size'] = int(data[2])
+            d['seen'] = False
+	except IndexError, e:
+            print("Corrupted line in cachefile " + cachefile + " : " + l)
+	    raise e
     return cache
 
 def mkdirhier(dir):
recipes/stage-manager/stagemanager-native_0.0.1.bb +1 -1
index 5708045..4357517 100644
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \
Signature · 1 line
1.6.3.3
Acked-by on v1 1/1
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Looks good to me,

Quoted 47 lines · Mickaël Chazaux

Sometimes stage-manager crashes with this message :
Traceback (most recent call last):
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 79, in <module>
cache = read_cache(options.cachefile)
File "/home/mchazaux/projet/OE/openembedded/recipes/stage-manager/files/stage-manager",
line 34, in read_cache
cache[data[0]]['ts'] = int(data[1])
IndexError: list index out of range

This is due to a corrupted cache file. This patch adds an error message telling the cause of the crash to the user.

---
 recipes/stage-manager/files/stage-manager          |   14 +++++++++-----
 recipes/stage-manager/stagemanager-native_0.0.1.bb |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)
recipes/stage-manager/files/stage-manager +9 -5
index 536d1af..93196ff 100755
@@ -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('|')
+            d = cache[data[0]] = {}
+            d['ts'] = int(data[1])
+            d['size'] = int(data[2])
+            d['seen'] = False
+	except IndexError, e:
+            print("Corrupted line in cachefile " + cachefile + " : " + l)
+	    raise e
     return cache
 
 def mkdirhier(dir):
recipes/stage-manager/stagemanager-native_0.0.1.bb +0 -0
index 5708045..4357517 100644

recipes/stage-manager/stagemanager-native_0.0.1.bb line 5

Quoted 6 lines
recipes/stage-manager/stagemanager-native_0.0.1.bb +1 -1
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFL1WjkMkyGM64RGpERAt8oAJ9mwOyDvMIdKcnwwwT+FKNCf+96SACgm+DY c1xLNKOJQXZjZurAa6nNGiU=
=QDGW
-----END PGP SIGNATURE-----

Acked-by
#2 lore raw
Quoted 8 lines · Koen Kooi

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Looks good to me,

Same here.

Might also be worth catching ValueError there, to be safe (int("foo") raises that :).

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#3 lore raw

Hi,

2010/4/26 Chris Larson <[email protected]>:

Quoted 10 lines · Koen Kooi
Quoted 9 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Looks good to me,

Quoted 6 lines

Same here.

Might also be worth catching ValueError there, to be safe (int("foo") raises that :).

I'll add that. I am also unsure on what to do in case of an error. Is it possible to ignore them? In that case, failing silently may be better.

Regards,

Mickael
Adeneo Embedded - Adetel Group
2, chemin du Ruisseau
69134 ECULLY - FRANCE
Tél. : +33 (0)4 72 18 08 40 - Fax : +33 (0)4 72 18 08 41