i18n: fix string puzzles in error messages

Do not split the error messages and the error details, but rather use a
single string with proper placeholders. This avoids string puzzles.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
This commit is contained in:
Pino Toscano 2020-07-14 09:41:49 +02:00 committed by Cole Robinson
parent ed836c7138
commit 71f034d6b6
15 changed files with 70 additions and 40 deletions

View File

@ -806,10 +806,12 @@ class vmmCloneVM(vmmGObjectUI):
self.reset_finish_cursor() self.reset_finish_cursor()
if error is not None: if error is not None:
msg = (_("Error creating virtual machine clone '%s'") % error = (_("Error creating virtual machine clone '%(vm)s': "
self.clone_design.clone_name) "%(error)s") % {
msg += ": %s" % error "vm": self.clone_design.clone_name,
self.err.show_err(msg, details=details) "error": error,
})
self.err.show_err(error, details=details)
return return
conn.schedule_priority_tick(pollvm=True) conn.schedule_priority_tick(pollvm=True)

View File

@ -598,11 +598,16 @@ class vmmConnection(vmmGObject):
except Exception as fixerr: except Exception as fixerr:
log.debug("Failed to redefine original %s!", log.debug("Failed to redefine original %s!",
obj.class_name(), exc_info=True) obj.class_name(), exc_info=True)
msg = (_("%s rename failed. Attempting to " msg = _("%(object)s rename failed. Attempting to recover also "
"recover also failed") % (obj.class_name())) "failed.\n"
msg += "\n\n" "\n"
msg += ("Original error: %s\n\n" % str(renameerr)) "Original error: %(origerror)s\n"
msg += ("Recover error: %s" % str(fixerr)) "\n"
"Recover error: %s") % {
"object": obj.class_name(),
"origerror": str(renameerr),
"recovererror": str(fixerr),
}
raise RuntimeError(msg) raise RuntimeError(msg)
raise raise
finally: finally:

View File

@ -1923,7 +1923,7 @@ class vmmCreateVM(vmmGObjectUI):
self._show_customize_dialog(guest, installer) self._show_customize_dialog(guest, installer)
except Exception as e: except Exception as e:
self.reset_finish_cursor() self.reset_finish_cursor()
self.err.show_err(_("Error starting installation: ") + str(e)) self.err.show_err(_("Error starting installation: %s") % str(e))
return return
def _cleanup_customize_window(self): def _cleanup_customize_window(self):

View File

@ -199,9 +199,10 @@ class _vmmDeleteBase(vmmGObjectUI):
self._delete_vm(vm) self._delete_vm(vm)
except Exception as e: except Exception as e:
error = ( error = _("Error deleting virtual machine '%(vm)s': %(error)s") % {
(_("Error deleting virtual machine '%s'") % vm.get_name()) + "vm": vm.get_name(),
(": %s") % str(e)) "error": str(e),
}
details = "".join(traceback.format_exc()) details = "".join(traceback.format_exc())
storage_errstr = "" storage_errstr = ""

View File

@ -736,7 +736,7 @@ class vmmConsolePages(vmmGObjectUI):
except Exception as e: except Exception as e:
log.exception("Error connection to graphical console") log.exception("Error connection to graphical console")
self._activate_unavailable_page( 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): def _set_credentials(self, src_ignore=None):
passwd = self.widget("console-auth-password") passwd = self.widget("console-auth-password")

View File

@ -461,8 +461,10 @@ class VNCViewer(Viewer):
self._sockfd = sock self._sockfd = sock
except Exception as e: except Exception as e:
raise RuntimeError( raise RuntimeError(
(_("Error opening socket path '%s'") % self._ginfo.gsocket) + _("Error opening socket path '%(path)s': %(error)s") % {
(": %s" % e)) "path": self._ginfo.gsocket,
"error": e,
})
fd = self._sockfd.fileno() fd = self._sockfd.fileno()
if fd < 0: if fd < 0:

View File

@ -211,8 +211,10 @@ class vmmNetworkList(vmmGObjectUI):
log.debug("Started network '%s'", devname) log.debug("Started network '%s'", devname)
except Exception as e: except Exception as e:
return self.err.show_err( return self.err.show_err(
(_("Could not start virtual network '%s'") % devname) + _("Could not start virtual network '%(device)s': %(error)s") % {
(": %s") % str(e)) "device": devname,
"error": str(e),
})
def _find_rowiter_for_dev(self, net): def _find_rowiter_for_dev(self, net):
nettype = net.type nettype = net.type

View File

@ -239,7 +239,7 @@ class VMActionUI(object):
def errorcb(error, details): def errorcb(error, details):
# This is run from the main thread # This is run from the main thread
res = src.err.show_err( res = src.err.show_err(
_("Error restoring domain") + ": " + error, _("Error restoring domain: %s") % error,
details=details, details=details,
text2=_( text2=_(
"The domain could not be restored. Would you like\n" "The domain could not be restored. Would you like\n"

View File

@ -489,8 +489,10 @@ def get_domain_and_guest(conn, domstr):
else: else:
raise raise
except libvirt.libvirtError as e: except libvirt.libvirtError as e:
fail((_("Could not find domain '%s'") % domstr) + fail(_("Could not find domain '%(domain)s': %(error)s") % {
(": " + str(e))) "domain": domstr,
"error": str(e),
})
state = domain.info()[0] state = domain.info()[0]
active_xmlobj = None active_xmlobj = None

View File

@ -43,8 +43,10 @@ def _replace_vm(conn, name):
vm.undefine() vm.undefine()
except libvirt.libvirtError as e: # pragma: no cover except libvirt.libvirtError as e: # pragma: no cover
raise RuntimeError( raise RuntimeError(
(_("Could not remove old vm '%s'") % name) + _("Could not remove old vm '%(vm)s': %(error)s") % {
(": " + str(e))) "vm": name,
"error": str(e),
})
class Cloner(object): class Cloner(object):

View File

@ -623,10 +623,10 @@ class CloneStorageCreator(_StorageCreator):
meter.update(i) meter.update(i)
except OSError as e: # pragma: no cover except OSError as e: # pragma: no cover
msg = (_("Error cloning diskimage " msg = (_("Error cloning diskimage "
"%(inputpath)s to %(outputpath)s") % "%(inputpath)s to %(outputpath)s: %(error)s") %
{"inputpath": self._input_path, {"inputpath": self._input_path,
"outputpath": self._output_path}) "outputpath": self._output_path,
msg += ": " + str(e) "error": str(e)})
raise RuntimeError(msg) raise RuntimeError(msg)
finally: finally:
if src_fd is not None: if src_fd is not None:

View File

@ -68,8 +68,10 @@ class InstallerTreeMedia(object):
"from the local directory mount point.") "from the local directory mount point.")
raise ValueError( raise ValueError(
(_("Validating install media '%s' failed") % str(path)) + _("Validating install media '%(media)s' failed: %(error)s") % {
(": %s" % e)) "media": str(path),
"error": str(e),
})
@staticmethod @staticmethod
def get_system_scratchdir(guest): def get_system_scratchdir(guest):

View File

@ -68,8 +68,10 @@ class _URLFetcher(object):
urlobj, size = self._grabber(url) urlobj, size = self._grabber(url)
except Exception as e: except Exception as e:
raise ValueError( raise ValueError(
(_("Couldn't acquire file %s") % url) + _("Couldn't acquire file %(url)s: %(error)s") % {
(": %s" % str(e))) "url": url,
"error": str(e),
})
log.debug("Fetching URI: %s", url) log.debug("Fetching URI: %s", url)
self.meter.start( self.meter.start(
@ -246,8 +248,10 @@ class _FTPURLFetcher(_URLFetcher):
self._ftp.voidcmd("TYPE I") self._ftp.voidcmd("TYPE I")
except Exception as e: # pragma: no cover except Exception as e: # pragma: no cover
raise ValueError( raise ValueError(
(_("Opening URL %s failed") % self.location) + _("Opening URL %(url)s failed: %(error)s") % {
(": %s" % str(e))) "url": self.location,
"error": str(e),
})
def _grabber(self, url): def _grabber(self, url):
""" """

View File

@ -163,8 +163,10 @@ class StoragePool(_StorageObject):
return defpool return defpool
except Exception as e: # pragma: no cover except Exception as e: # pragma: no cover
raise RuntimeError( raise RuntimeError(
(_("Couldn't create default storage pool '%s'") % path) + _("Couldn't create default storage pool '%(path)s': %(error)s") % {
(": %s" % str(e))) "path": path,
"error": str(e),
})
@staticmethod @staticmethod
def lookup_pool_by_path(conn, path): def lookup_pool_by_path(conn, path):

View File

@ -243,8 +243,10 @@ def start_domain_transient(conn, xmlobj, devs, action, confirm):
try: try:
dom = conn.createXML(xmlobj.get_xml()) dom = conn.createXML(xmlobj.get_xml())
except libvirt.libvirtError as e: except libvirt.libvirtError as e:
fail((_("Failed starting domain '%s'") % xmlobj.name) + fail(_("Failed starting domain '%(domain)s': %(error)s") % {
(": %s" % e)) "vm": xmlobj.name,
"error": e,
})
else: else:
print_stdout(_("Domain '%s' started successfully.") % xmlobj.name) print_stdout(_("Domain '%s' started successfully.") % xmlobj.name)
return dom return dom
@ -278,8 +280,10 @@ def update_changes(domain, devs, action, confirm):
elif action == "update": elif action == "update":
domain.updateDeviceFlags(xml, libvirt.VIR_DOMAIN_AFFECT_LIVE) domain.updateDeviceFlags(xml, libvirt.VIR_DOMAIN_AFFECT_LIVE)
except libvirt.libvirtError as e: except libvirt.libvirtError as e:
fail((_("Error attempting device action %s") % action) + fail(_("Error attempting device action %(action)s: %(error)s") % {
(": %s" % e)) "action": action,
"error": e,
})
# Test driver doesn't support device hotplug so we can't reach this # Test driver doesn't support device hotplug so we can't reach this
print_stdout(_("Device %s successful.") % action) # pragma: no cover print_stdout(_("Device %s successful.") % action) # pragma: no cover
@ -505,8 +509,10 @@ def main(conn=None):
try: try:
dom.create() dom.create()
except libvirt.libvirtError as e: # pragma: no cover except libvirt.libvirtError as e: # pragma: no cover
fail((_("Failed starting domain '%s'") % inactive_xmlobj.name) + fail(_("Failed starting domain '%(domain)s': %(error)s") % {
(": " % e)) "domain": inactive_xmlobj.name,
"error": e,
})
print_stdout(_("Domain '%s' started successfully.") % print_stdout(_("Domain '%s' started successfully.") %
inactive_xmlobj.name) inactive_xmlobj.name)