Patchwork [3,of,9,sethelp] error: add a new NotAFunction error type

login
register
mail settings
Submitter Augie Fackler
Date Feb. 4, 2015, 6:15 p.m.
Message ID <04c92caf02b761ce3e2f.1423073708@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7666/
State Changes Requested
Headers show

Comments

Augie Fackler - Feb. 4, 2015, 6:15 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1422300661 18000
#      Mon Jan 26 14:31:01 2015 -0500
# Node ID 04c92caf02b761ce3e2f46618b6b93e09e2b1bd3
# Parent  31f51746469a974042b75e32095e20b565bba8f4
error: add a new NotAFunction error type

This will be used by the revset and fileset code to communicate more
specific errors to higher levels so that we might be able to offer
suggestions about what function might have been similar.
Matt Mackall - Feb. 4, 2015, 10:25 p.m.
On Wed, 2015-02-04 at 13:15 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1422300661 18000
> #      Mon Jan 26 14:31:01 2015 -0500
> # Node ID 04c92caf02b761ce3e2f46618b6b93e09e2b1bd3
> # Parent  31f51746469a974042b75e32095e20b565bba8f4
> error: add a new NotAFunction error type

I like the idea of this series, but I think you may not be thinking big
enough. We've also got template keywords and such to complain about,
never mind command names. So I think we need a more generic
UnknownIdentifier exception and probably a more widely available utility
function to find the matches.

Also, my failure mode here is often doing something like "default()" -
trying to treat a symbol as a function.
Augie Fackler - Feb. 5, 2015, 10:45 p.m.
On Feb 4, 2015, at 5:25 PM, Matt Mackall <mpm@selenic.com> wrote:

> On Wed, 2015-02-04 at 13:15 -0500, Augie Fackler wrote:
>> # HG changeset patch
>> # User Augie Fackler <augie@google.com>
>> # Date 1422300661 18000
>> #      Mon Jan 26 14:31:01 2015 -0500
>> # Node ID 04c92caf02b761ce3e2f46618b6b93e09e2b1bd3
>> # Parent  31f51746469a974042b75e32095e20b565bba8f4
>> error: add a new NotAFunction error type
> 
> I like the idea of this series, but I think you may not be thinking big
> enough. We've also got template keywords and such to complain about,
> never mind command names. So I think we need a more generic
> UnknownIdentifier exception and probably a more widely available utility
> function to find the matches.

*nod* I viewed this mostly as a prelude to handling other things. At least command names came to mind.

Okay if I do a resend of this series with NotAFunction renamed to UnknownIdentifier or UnknownSymbol? Do you have a preference between those two?


> 
> Also, my failure mode here is often doing something like "default()" -
> trying to treat a symbol as a function.

Yeah, I'll put that on the list of things I want to tackle.

> 
> -- 
> Mathematics is the supreme nostalgia of our time.
> 
>
Matt Mackall - Feb. 5, 2015, 10:49 p.m.
On Thu, 2015-02-05 at 17:45 -0500, Augie Fackler wrote:
> On Feb 4, 2015, at 5:25 PM, Matt Mackall <mpm@selenic.com> wrote:
> 
> > On Wed, 2015-02-04 at 13:15 -0500, Augie Fackler wrote:
> >> # HG changeset patch
> >> # User Augie Fackler <augie@google.com>
> >> # Date 1422300661 18000
> >> #      Mon Jan 26 14:31:01 2015 -0500
> >> # Node ID 04c92caf02b761ce3e2f46618b6b93e09e2b1bd3
> >> # Parent  31f51746469a974042b75e32095e20b565bba8f4
> >> error: add a new NotAFunction error type
> > 
> > I like the idea of this series, but I think you may not be thinking big
> > enough. We've also got template keywords and such to complain about,
> > never mind command names. So I think we need a more generic
> > UnknownIdentifier exception and probably a more widely available utility
> > function to find the matches.
> 
> *nod* I viewed this mostly as a prelude to handling other things. At least command names came to mind.
> 
> Okay if I do a resend of this series with NotAFunction renamed to UnknownIdentifier or UnknownSymbol? Do you have a preference between those two?

I picked Identifier because we already have a subset of symbols known as
symbols. I'd take this with this and the difflib thing.

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -63,6 +63,15 @@  class OutOfBandError(Exception):
 class ParseError(Exception):
     """Raised when parsing config files and {rev,file}sets (msg[, pos])"""
 
+class NotAFunction(ParseError):
+    """Exception raised when a {rev,file}set references an unknown function"""
+
+    def __init__(self, function, symbols):
+        from i18n import _
+        ParseError.__init__(self, _("not a function: %s") % function)
+        self.function = function
+        self.symbols = symbols
+
 class RepoError(Exception):
     def __init__(self, *args, **kw):
         Exception.__init__(self, *args)