Patchwork [2,of,6,V2] revset: factor out composing error message for ParseError to reuse

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 10, 2015, 2:25 p.m.
Message ID <242955b8831a4d125706.1420899942@feefifofum>
Download mbox | patch
Permalink /patch/7419/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Jan. 10, 2015, 2:25 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1420899491 -32400
#      Sat Jan 10 23:18:11 2015 +0900
# Node ID 242955b8831a4d125706acdee83b2257bd023dab
# Parent  225c17b09cc4220ae020fae91ea9044afd10ee86
revset: factor out composing error message for ParseError to reuse

This patch defines the composing function not in "ParseError" class but
in "revset" module, because:

  - "_()" shouldn't be used in "ParseError", to avoid adding "from
    i18n import _" i18n" to "error" module

  - generalizing message composition of"ParseError" for all code paths
    other than revset isn't the purpose of this patch

    we should also take care of showing "unexpected leading
    whitespace" for some code paths, to generalize widely.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -239,6 +239,14 @@ 
         pos += 1
     yield ('end', None, pos)
 
+def parseerrordetail(inst):
+    """Compose error message from specified ParseError object
+    """
+    if len(inst.args) > 1:
+        return _('at %s: %s') % (inst.args[1], inst.args[0])
+    else:
+        return inst.args[0]
+
 # helpers
 
 def getstring(x, err):
@@ -2109,10 +2117,7 @@ 
             # Check for placeholder injection
             _checkaliasarg(self.replacement, self.args)
         except error.ParseError, inst:
-            if len(inst.args) > 1:
-                self.error = _('at %s: %s') % (inst.args[1], inst.args[0])
-            else:
-                self.error = inst.args[0]
+            self.error = parseerrordetail(inst)
 
 def _getalias(aliases, tree):
     """If tree looks like an unexpanded alias, return it. Return None