[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided



Hi,
thanks for advice. Here's new and corrected version of the patch. Well, the error here is IndexError, when an error occurs so the IndexError is catched and not KeyError. I have also tried it with KeyError but it was not working so IndexError is catched here.

Michal

Ian Jackson wrote:
Michal Novotny writes ("[Xen-devel] [PATCH] Make PyGrub run first entry in grub 
config when invalid default boot option provided"):
-    img = g.cf.images[sel]
+    try:
+        img = g.cf.images[sel]
+    except:

It is not correct to do this on all exceptions.  (This is a common
mistake in Python.)  I assume that in your error case the images array
doesn't have the relevant entry and that your code should read:
  +        img = g.cf.images[sel]
  +    except KeyError:

Ian.

diff -r e1562a36094e tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Thu Mar 19 17:04:06 2009 +0000
+++ b/tools/pygrub/src/pygrub   Fri Mar 20 15:09:31 2009 +0100
@@ -530,7 +530,11 @@
         print "No kernel image selected!"
         sys.exit(1)
 
-    img = g.cf.images[sel]
+    try:
+        img = g.cf.images[sel]
+    except IndexError:
+        img = g.cf.images[0]
+
 
     grubcfg = { "kernel": None, "ramdisk": None, "args": None }
 
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.