Do not split the error messages and the error details, but rather use a single string with proper placeholders. This avoids string puzzles. Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx> --- virtManager/clone.py | 10 ++++++---- virtManager/connection.py | 15 ++++++++++----- virtManager/createvm.py | 2 +- virtManager/delete.py | 7 ++++--- virtManager/details/console.py | 2 +- virtManager/details/viewers.py | 6 ++++-- virtManager/device/netlist.py | 6 ++++-- virtManager/vmmenu.py | 2 +- virtinst/cli.py | 6 ++++-- virtinst/cloner.py | 6 ++++-- virtinst/diskbackend.py | 6 +++--- virtinst/install/installertreemedia.py | 6 ++++-- virtinst/install/urlfetcher.py | 12 ++++++++---- virtinst/storage.py | 6 ++++-- virtinst/virtxml.py | 18 ++++++++++++------ 15 files changed, 70 insertions(+), 40 deletions(-) diff --git a/virtManager/clone.py b/virtManager/clone.py index ecd56b5d..43a04802 100644 --- a/virtManager/clone.py +++ b/virtManager/clone.py @@ -806,10 +806,12 @@ class vmmCloneVM(vmmGObjectUI): self.reset_finish_cursor() if error is not None: - msg = (_("Error creating virtual machine clone '%s'") % - self.clone_design.clone_name) - msg += ": %s" % error - self.err.show_err(msg, details=details) + error = (_("Error creating virtual machine clone '%(vm)s': " + "%(error)s") % { + "vm": self.clone_design.clone_name, + "error": error, + }) + self.err.show_err(error, details=details) return conn.schedule_priority_tick(pollvm=True) diff --git a/virtManager/connection.py b/virtManager/connection.py index bed6f5d5..01d5e03a 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -598,11 +598,16 @@ class vmmConnection(vmmGObject): except Exception as fixerr: log.debug("Failed to redefine original %s!", obj.class_name(), exc_info=True) - msg = (_("%s rename failed. Attempting to " - "recover also failed") % (obj.class_name())) - msg += "\n\n" - msg += ("Original error: %s\n\n" % str(renameerr)) - msg += ("Recover error: %s" % str(fixerr)) + msg = _("%(object)s rename failed. Attempting to recover also " + "failed.\n" + "\n" + "Original error: %(origerror)s\n" + "\n" + "Recover error: %s") % { + "object": obj.class_name(), + "origerror": str(renameerr), + "recovererror": str(fixerr), + } raise RuntimeError(msg) raise finally: diff --git a/virtManager/createvm.py b/virtManager/createvm.py index 5f15f5c3..1120ea2a 100644 --- a/virtManager/createvm.py +++ b/virtManager/createvm.py @@ -1923,7 +1923,7 @@ class vmmCreateVM(vmmGObjectUI): self._show_customize_dialog(guest, installer) except Exception as e: self.reset_finish_cursor() - self.err.show_err(_("Error starting installation: ") + str(e)) + self.err.show_err(_("Error starting installation: %s") % str(e)) return def _cleanup_customize_window(self): diff --git a/virtManager/delete.py b/virtManager/delete.py index 40284505..28edc727 100644 --- a/virtManager/delete.py +++ b/virtManager/delete.py @@ -199,9 +199,10 @@ class _vmmDeleteBase(vmmGObjectUI): self._delete_vm(vm) except Exception as e: - error = ( - (_("Error deleting virtual machine '%s'") % vm.get_name()) + - (": %s") % str(e)) + error = _("Error deleting virtual machine '%(vm)s': %(error)s") % { + "vm": vm.get_name(), + "error": str(e), + } details = "".join(traceback.format_exc()) storage_errstr = "" diff --git a/virtManager/details/console.py b/virtManager/details/console.py index 193e79eb..ae9b85ed 100644 --- a/virtManager/details/console.py +++ b/virtManager/details/console.py @@ -736,7 +736,7 @@ class vmmConsolePages(vmmGObjectUI): except Exception as e: log.exception("Error connection to graphical console") self._activate_unavailable_page( - _("Error connecting to graphical console") + ":\n%s" % e) + _("Error connecting to graphical console:\n%s") % e) def _set_credentials(self, src_ignore=None): passwd = self.widget("console-auth-password") diff --git a/virtManager/details/viewers.py b/virtManager/details/viewers.py index bcefa86a..4ae0e668 100644 --- a/virtManager/details/viewers.py +++ b/virtManager/details/viewers.py @@ -461,8 +461,10 @@ class VNCViewer(Viewer): self._sockfd = sock except Exception as e: raise RuntimeError( - (_("Error opening socket path '%s'") % self._ginfo.gsocket) + - (": %s" % e)) + _("Error opening socket path '%(path)s': %(error)s") % { + "path": self._ginfo.gsocket, + "error": e, + }) fd = self._sockfd.fileno() if fd < 0: diff --git a/virtManager/device/netlist.py b/virtManager/device/netlist.py index 29aeac50..cfd7a442 100644 --- a/virtManager/device/netlist.py +++ b/virtManager/device/netlist.py @@ -211,8 +211,10 @@ class vmmNetworkList(vmmGObjectUI): log.debug("Started network '%s'", devname) except Exception as e: return self.err.show_err( - (_("Could not start virtual network '%s'") % devname) + - (": %s") % str(e)) + _("Could not start virtual network '%(device)s': %(error)s") % { + "device": devname, + "error": str(e), + }) def _find_rowiter_for_dev(self, net): nettype = net.type diff --git a/virtManager/vmmenu.py b/virtManager/vmmenu.py index a5b4410f..5883ce34 100644 --- a/virtManager/vmmenu.py +++ b/virtManager/vmmenu.py @@ -239,7 +239,7 @@ class VMActionUI(object): def errorcb(error, details): # This is run from the main thread res = src.err.show_err( - _("Error restoring domain") + ": " + error, + _("Error restoring domain: %s") % error, details=details, text2=_( "The domain could not be restored. Would you like\n" diff --git a/virtinst/cli.py b/virtinst/cli.py index 37b1f617..ed9fd911 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -489,8 +489,10 @@ def get_domain_and_guest(conn, domstr): else: raise except libvirt.libvirtError as e: - fail((_("Could not find domain '%s'") % domstr) + - (": " + str(e))) + fail(_("Could not find domain '%(domain)s': %(error)s") % { + "domain": domstr, + "error": str(e), + }) state = domain.info()[0] active_xmlobj = None diff --git a/virtinst/cloner.py b/virtinst/cloner.py index 7d4db4f3..d3ba1bfa 100644 --- a/virtinst/cloner.py +++ b/virtinst/cloner.py @@ -43,8 +43,10 @@ def _replace_vm(conn, name): vm.undefine() except libvirt.libvirtError as e: # pragma: no cover raise RuntimeError( - (_("Could not remove old vm '%s'") % name) + - (": " + str(e))) + _("Could not remove old vm '%(vm)s': %(error)s") % { + "vm": name, + "error": str(e), + }) class Cloner(object): diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py index f35964db..0dcfe663 100644 --- a/virtinst/diskbackend.py +++ b/virtinst/diskbackend.py @@ -623,10 +623,10 @@ class CloneStorageCreator(_StorageCreator): meter.update(i) except OSError as e: # pragma: no cover msg = (_("Error cloning diskimage " - "%(inputpath)s to %(outputpath)s") % + "%(inputpath)s to %(outputpath)s: %(error)s") % {"inputpath": self._input_path, - "outputpath": self._output_path}) - msg += ": " + str(e) + "outputpath": self._output_path, + "error": str(e)}) raise RuntimeError(msg) finally: if src_fd is not None: diff --git a/virtinst/install/installertreemedia.py b/virtinst/install/installertreemedia.py index d39d346d..318c56d0 100644 --- a/virtinst/install/installertreemedia.py +++ b/virtinst/install/installertreemedia.py @@ -68,8 +68,10 @@ class InstallerTreeMedia(object): "from the local directory mount point.") raise ValueError( - (_("Validating install media '%s' failed") % str(path)) + - (": %s" % e)) + _("Validating install media '%(media)s' failed: %(error)s") % { + "media": str(path), + "error": str(e), + }) @staticmethod def get_system_scratchdir(guest): diff --git a/virtinst/install/urlfetcher.py b/virtinst/install/urlfetcher.py index 70755bcd..d539e142 100644 --- a/virtinst/install/urlfetcher.py +++ b/virtinst/install/urlfetcher.py @@ -68,8 +68,10 @@ class _URLFetcher(object): urlobj, size = self._grabber(url) except Exception as e: raise ValueError( - (_("Couldn't acquire file %s") % url) + - (": %s" % str(e))) + _("Couldn't acquire file %(url)s: %(error)s") % { + "url": url, + "error": str(e), + }) log.debug("Fetching URI: %s", url) self.meter.start( @@ -246,8 +248,10 @@ class _FTPURLFetcher(_URLFetcher): self._ftp.voidcmd("TYPE I") except Exception as e: # pragma: no cover raise ValueError( - (_("Opening URL %s failed") % self.location) + - (": %s" % str(e))) + _("Opening URL %(url)s failed: %(error)s") % { + "url": self.location, + "error": str(e), + }) def _grabber(self, url): """ diff --git a/virtinst/storage.py b/virtinst/storage.py index 93fe3aa3..796bc3bd 100644 --- a/virtinst/storage.py +++ b/virtinst/storage.py @@ -163,8 +163,10 @@ class StoragePool(_StorageObject): return defpool except Exception as e: # pragma: no cover raise RuntimeError( - (_("Couldn't create default storage pool '%s'") % path) + - (": %s" % str(e))) + _("Couldn't create default storage pool '%(path)s': %(error)s") % { + "path": path, + "error": str(e), + }) @staticmethod def lookup_pool_by_path(conn, path): diff --git a/virtinst/virtxml.py b/virtinst/virtxml.py index 95752a69..5b36837e 100644 --- a/virtinst/virtxml.py +++ b/virtinst/virtxml.py @@ -243,8 +243,10 @@ def start_domain_transient(conn, xmlobj, devs, action, confirm): try: dom = conn.createXML(xmlobj.get_xml()) except libvirt.libvirtError as e: - fail((_("Failed starting domain '%s'") % xmlobj.name) + - (": %s" % e)) + fail(_("Failed starting domain '%(domain)s': %(error)s") % { + "vm": xmlobj.name, + "error": e, + }) else: print_stdout(_("Domain '%s' started successfully.") % xmlobj.name) return dom @@ -278,8 +280,10 @@ def update_changes(domain, devs, action, confirm): elif action == "update": domain.updateDeviceFlags(xml, libvirt.VIR_DOMAIN_AFFECT_LIVE) except libvirt.libvirtError as e: - fail((_("Error attempting device action %s") % action) + - (": %s" % e)) + fail(_("Error attempting device action %(action)s: %(error)s") % { + "action": action, + "error": e, + }) # Test driver doesn't support device hotplug so we can't reach this print_stdout(_("Device %s successful.") % action) # pragma: no cover @@ -505,8 +509,10 @@ def main(conn=None): try: dom.create() except libvirt.libvirtError as e: # pragma: no cover - fail((_("Failed starting domain '%s'") % inactive_xmlobj.name) + - (": " % e)) + fail(_("Failed starting domain '%(domain)s': %(error)s") % { + "domain": inactive_xmlobj.name, + "error": e, + }) print_stdout(_("Domain '%s' started successfully.") % inactive_xmlobj.name) -- 2.26.2