From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Novotny Subject: Re: [PATCH] Make PyGrub run first entry in grub config when invalid default boot option provided Date: Tue, 24 Mar 2009 10:21:38 +0100 Message-ID: <49C8A622.9090509@redhat.com> References: <49C3A4D6.5050501@redhat.com> <18887.49660.721664.393967@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060106020706030900000103" Return-path: In-Reply-To: <18887.49660.721664.393967@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------060106020706030900000103 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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. > --------------060106020706030900000103 Content-Type: text/plain; name="xen-pygrub-invalid-default-configuration.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="xen-pygrub-invalid-default-configuration.patch" 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 } --------------060106020706030900000103 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------060106020706030900000103--