changeset 3072:bc3fe3b5b785

Never apply string formatting to generated errors with util.Abort. Otherwise error messages containing % chars yield errors or worse. Fixed (hopefully) all users of util.Abort.
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 08 Sep 2006 09:36:18 +0200
parents 547d1a4aa105
children 24c1db20990c
files hgext/mq.py mercurial/cmdutil.py mercurial/commands.py mercurial/hg.py mercurial/httprepo.py mercurial/localrepo.py
diffstat 6 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/hgext/mq.py	Fri Sep 08 09:36:18 2006 +0200
@@ -1479,7 +1479,7 @@
     if not files:
         raise util.Abort(_('qfold requires at least one patch name'))
     if not q.check_toppatch(repo):
-        raise util.Abort(_('No patches applied\n'))
+        raise util.Abort(_('No patches applied'))
 
     message = commands.logmessage(opts)
     if opts['edit']:
--- a/mercurial/cmdutil.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/mercurial/cmdutil.py	Fri Sep 08 09:36:18 2006 +0200
@@ -53,8 +53,8 @@
             i += 1
         return ''.join(newname)
     except KeyError, inst:
-        raise util.Abort(_("invalid format spec '%%%s' in output file name"),
-                    inst.args[0])
+        raise util.Abort(_("invalid format spec '%%%s' in output file name") %
+                         inst.args[0])
 
 def make_file(repo, pat, node=None,
               total=None, seqno=None, revwidth=None, mode='wb', pathname=None):
--- a/mercurial/commands.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/mercurial/commands.py	Fri Sep 08 09:36:18 2006 +0200
@@ -274,7 +274,7 @@
         try:
             num = repo.changelog.rev(repo.lookup(val))
         except KeyError:
-            raise util.Abort(_('invalid revision identifier %s'), val)
+            raise util.Abort(_('invalid revision identifier %s') % val)
     return num
 
 def revpair(ui, repo, revs):
@@ -341,7 +341,7 @@
     try:
         if filename:
             if os.path.exists(filename):
-                raise util.Abort(_("file '%s' already exists"), filename)
+                raise util.Abort(_("file '%s' already exists") % filename)
             fh = open(filename, "wb")
         else:
             fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
@@ -1269,7 +1269,7 @@
     try:
         ui.write(r.revision(r.lookup(rev)))
     except KeyError:
-        raise util.Abort(_('invalid revision identifier %s'), rev)
+        raise util.Abort(_('invalid revision identifier %s') % rev)
 
 def debugindex(ui, file_):
     """dump the contents of an index file"""
@@ -2484,7 +2484,7 @@
     try:
         httpd = hgweb.server.create_server(ui, repo)
     except socket.error, inst:
-        raise util.Abort(_('cannot start server: ') + inst.args[1])
+        raise util.Abort(_('cannot start server: %s') % inst.args[1])
 
     if ui.verbose:
         addr, port = httpd.socket.getsockname()
@@ -2734,7 +2734,7 @@
             repo.ui.warn(_("Using head %s for branch %s\n")
                          % (short(node), branch))
         else:
-            raise util.Abort(_("branch %s not found\n") % (branch))
+            raise util.Abort(_("branch %s not found") % branch)
     else:
         node = node and repo.lookup(node) or repo.changelog.tip()
     return node
@@ -3449,7 +3449,7 @@
         u.warn(_("abort: could not lock %s: %s\n") %
                (inst.desc or inst.filename, inst.strerror))
     except revlog.RevlogError, inst:
-        u.warn(_("abort: "), inst, "!\n")
+        u.warn(_("abort: %s!\n") % inst)
     except util.SignalInterrupt:
         u.warn(_("killed!\n"))
     except KeyboardInterrupt:
@@ -3482,7 +3482,7 @@
         else:
             u.warn(_("abort: %s\n") % inst.strerror)
     except util.Abort, inst:
-        u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
+        u.warn(_("abort: %s\n") % inst)
     except TypeError, inst:
         # was this an argument error?
         tb = traceback.extract_tb(sys.exc_info()[2])
--- a/mercurial/hg.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/mercurial/hg.py	Fri Sep 08 09:36:18 2006 +0200
@@ -115,7 +115,7 @@
     source = localpath(source)
 
     if os.path.exists(dest):
-        raise util.Abort(_("destination '%s' already exists"), dest)
+        raise util.Abort(_("destination '%s' already exists") % dest)
 
     class DirCleanup(object):
         def __init__(self, dir_):
--- a/mercurial/httprepo.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/mercurial/httprepo.py	Fri Sep 08 09:36:18 2006 +0200
@@ -325,7 +325,7 @@
                     rfp.close()
             except socket.error, err:
                 if err[0] in (errno.ECONNRESET, errno.EPIPE):
-                    raise util.Abort(_('push failed: %s'), err[1])
+                    raise util.Abort(_('push failed: %s') % err[1])
                 raise util.Abort(err[1])
         finally:
             fp.close()
--- a/mercurial/localrepo.py	Fri Sep 08 02:16:16 2006 +0200
+++ b/mercurial/localrepo.py	Fri Sep 08 09:36:18 2006 +0200
@@ -133,7 +133,7 @@
             except Exception, exc:
                 if isinstance(exc, util.Abort):
                     self.ui.warn(_('error: %s hook failed: %s\n') %
-                                 (hname, exc.args[0] % exc.args[1:]))
+                                 (hname, exc.args[0]))
                 else:
                     self.ui.warn(_('error: %s hook raised an exception: '
                                    '%s\n') % (hname, exc))