Patchwork [5,of,5] revsetlang: raise ParseError to report invalid format character

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 7, 2018, 6:31 a.m.
Message ID <0955ec2eadf2cc4bb3ab.1515306715@mimosa>
Download mbox | patch
Permalink /patch/26598/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 7, 2018, 6:31 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491034368 -32400
#      Sat Apr 01 17:12:48 2017 +0900
# Node ID 0955ec2eadf2cc4bb3ab63263551a4bd8b5d810e
# Parent  235156e876401ee955e2db5b4cc1bae17f39e3f5
revsetlang: raise ParseError to report invalid format character

It's more common in revset and templater than raising Abort.

I have a couple more patches to address exceptions caused by bad format string
passed to revset() template function.

Patch

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -641,7 +641,8 @@  def formatspec(expr, *args):
             d = expr[pos]
             ret.append(listexp(list(next(argiter)), d))
         else:
-            raise error.Abort(_('unexpected revspec format character %s') % d)
+            raise error.ParseError(_('unexpected revspec format character %s')
+                                   % d)
         pos += 1
 
     return ''.join(ret)
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -4080,6 +4080,12 @@  default. join() should agree with the de
   5:13207e5a10d9fd28ec424934298e176197f2c67f,
   4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
 
+Invalid arguments passed to revset()
+
+  $ hg log -T '{revset("%whatever", 0)}\n'
+  hg: parse error: unexpected revspec format character w
+  [255]
+
 Test files function
 
   $ hg log -T "{rev}\n{join(files('*'), '\n')}\n"