All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add error handling to read_cache in stage-manager
@ 2010-04-26  9:33 Mickaël Chazaux
  2010-04-26 10:20 ` Koen Kooi
  0 siblings, 1 reply; 7+ messages in thread
From: Mickaël Chazaux @ 2010-04-26  9:33 UTC (permalink / raw)
  To: openembedded-devel; +Cc: 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(-)

diff --git a/recipes/stage-manager/files/stage-manager b/recipes/stage-manager/files/stage-manager
index 536d1af..93196ff 100755
--- a/recipes/stage-manager/files/stage-manager
+++ b/recipes/stage-manager/files/stage-manager
@@ -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):
diff --git a/recipes/stage-manager/stagemanager-native_0.0.1.bb b/recipes/stage-manager/stagemanager-native_0.0.1.bb
index 5708045..4357517 100644
--- a/recipes/stage-manager/stagemanager-native_0.0.1.bb
+++ b/recipes/stage-manager/stagemanager-native_0.0.1.bb
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \
-- 
1.6.3.3




^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] Add error handling to read_cache in stage-manager
@ 2010-04-27  7:53 Mickaël Chazaux
  2010-04-27 14:10 ` Chris Larson
  0 siblings, 1 reply; 7+ messages in thread
From: Mickaël Chazaux @ 2010-04-27  7:53 UTC (permalink / raw)
  To: openembedded-devel; +Cc: 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
and continues parsing ignoring the wrong line. The file is then properly
regenerated.
---
 recipes/stage-manager/files/stage-manager          |   14 +++++++++-----
 recipes/stage-manager/stagemanager-native_0.0.1.bb |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/recipes/stage-manager/files/stage-manager b/recipes/stage-manager/files/stage-manager
index 536d1af..039614f 100755
--- a/recipes/stage-manager/files/stage-manager
+++ b/recipes/stage-manager/files/stage-manager
@@ -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 = {}
+            d['ts'] = int(data[1])
+            d['size'] = int(data[2])
+            d['seen'] = False
+            cache[data[0]] = d
+	except (IndexError, ValueError):
+            print("Corrupted line in cachefile " + cachefile + " : " + l)
     return cache
 
 def mkdirhier(dir):
diff --git a/recipes/stage-manager/stagemanager-native_0.0.1.bb b/recipes/stage-manager/stagemanager-native_0.0.1.bb
index 5708045..4357517 100644
--- a/recipes/stage-manager/stagemanager-native_0.0.1.bb
+++ b/recipes/stage-manager/stagemanager-native_0.0.1.bb
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \
-- 
1.6.3.3




^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] Add error handling to read_cache in stage-manager
@ 2010-04-30 12:25 Mickaël Chazaux
  0 siblings, 0 replies; 7+ messages in thread
From: Mickaël Chazaux @ 2010-04-30 12:25 UTC (permalink / raw)
  To: openembedded-devel; +Cc: 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
and continues parsing ignoring the wrong line. The file is then properly
regenerated.

Signed-off-by: Mickaël Chazaux <mchazaux@adeneo-embedded.com>
---
 recipes/stage-manager/files/stage-manager          |   14 +++++++++-----
 recipes/stage-manager/stagemanager-native_0.0.1.bb |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/recipes/stage-manager/files/stage-manager b/recipes/stage-manager/files/stage-manager
index 536d1af..039614f 100755
--- a/recipes/stage-manager/files/stage-manager
+++ b/recipes/stage-manager/files/stage-manager
@@ -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 = {}
+            d['ts'] = int(data[1])
+            d['size'] = int(data[2])
+            d['seen'] = False
+            cache[data[0]] = d
+	except (IndexError, ValueError):
+            print("Corrupted line in cachefile " + cachefile + " : " + l)
     return cache
 
 def mkdirhier(dir):
diff --git a/recipes/stage-manager/stagemanager-native_0.0.1.bb b/recipes/stage-manager/stagemanager-native_0.0.1.bb
index 5708045..4357517 100644
--- a/recipes/stage-manager/stagemanager-native_0.0.1.bb
+++ b/recipes/stage-manager/stagemanager-native_0.0.1.bb
@@ -1,5 +1,5 @@
 DESCRIPTION = "Helper script for packaged-staging.bbclass"
-PR = "r11"
+PR = "r13"
 
 SRC_URI = "file://stage-manager \
            file://stage-manager-ipkg \
-- 
1.6.3.3




^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-04-30 12:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-26  9:33 [PATCH] Add error handling to read_cache in stage-manager Mickaël Chazaux
2010-04-26 10:20 ` Koen Kooi
2010-04-26 14:48   ` Chris Larson
2010-04-26 15:25     ` Mickael Chazaux
  -- strict thread matches above, loose matches on Subject: below --
2010-04-27  7:53 Mickaël Chazaux
2010-04-27 14:10 ` Chris Larson
2010-04-30 12:25 Mickaël Chazaux

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.