Re: [PATCH]: Print a better error message if the disk path doesn't exist

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

 



Cole Robinson wrote:
> 
> One gripe:
> 
>> +                except OSError:
>> +                    raise RuntimeError, "Path to diskimage "+self.path+" does not exist"
> 
> This error message is too general, as it doesn't take into account
> non-missing-path related errors, so this could swallow another legitimate
> error message.

I think you meant "this error message is too specific", but yes, I definitely
see your point.  I've refreshed the patch here, with a more generic error
message.  As a side benefit, this also catches the error if you run out of disk
space, plus gives useful information about any other errors os.open()/os.write()
might throw (like bad file permissions, etc).  This patch is against current
HEAD of python-virtinst.

Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>

diff -r 723b2d8b986a virtinst/Guest.py
--- a/virtinst/Guest.py	Thu Oct 11 11:46:47 2007 -0400
+++ b/virtinst/Guest.py	Mon Oct 29 13:40:41 2007 -0400
@@ -131,16 +131,19 @@ class VirtualDisk:
                              text=_("Creating storage file..."))
             fd = None
             try: 
-                fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
-                if self.sparse:
-                    os.lseek(fd, size_bytes, 0)
-                    os.write(fd, '\x00')
-                    progresscb.update(self.size)
-                else:
-                    buf = '\x00' * 1024 * 1024 # 1 meg of nulls
-                    for i in range(0, long(self.size * 1024L)):
-                        os.write(fd, buf)
-                        progresscb.update(long(i * 1024L * 1024L))
+                try:
+                    fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)
+                    if self.sparse:
+                        os.lseek(fd, size_bytes, 0)
+                        os.write(fd, '\x00')
+                        progresscb.update(self.size)
+                    else:
+                        buf = '\x00' * 1024 * 1024 # 1 meg of nulls
+                        for i in range(0, long(self.size * 1024L)):
+                            os.write(fd, buf)
+                            progresscb.update(long(i * 1024L * 1024L))
+                except OSError, detail:
+                    raise RuntimeError, "Error creating diskimage " + self.path + ": " + detail.strerror
             finally:
                 if fd is not None:
                     os.close(fd)
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux