Bug 3344 - templating: backtrace when using invalid expansion token
Summary: templating: backtrace when using invalid expansion token
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: keyword (show other bugs)
Version: unspecified
Hardware: All All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-31 12:10 UTC by Mel Flynn
Modified: 2012-10-26 13:30 UTC (History)
5 users (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mel Flynn 2012-03-31 12:10 UTC
Easy to reproduce:

[keywordmaps]
Author = {foo|utcdate}

You'll get a backtrace from which to conclude that 'foo' is not a valid
keyword, once you realize that text[0] refers to 'foo'. It's less subtle
when you misspelled "date" as "data".
Comment 1 Bugzilla 2012-05-12 09:29 UTC

--- Bug imported by bugzilla@serpentine.com 2012-05-12 09:29 EDT  ---

This bug was previously known as _bug_ 3343 at http://mercurial.selenic.com/bts/issue3343

Bug Status was UNCONFIRMED but everconfirmed was true
   Setting status to CONFIRMED

Comment 2 Patrick Mézard 2012-07-26 10:58 UTC
Test reproducing the issue:

  $ cat <<EOF >> $HGRCPATH
  > [extensions]
  > keyword =
  > [ui]
  > interactive = true
  > EOF

  $ hg init
  $ hg --quiet kwdemo "Branch = {foo|utcdate}"


I move it to the keyword component, but this is likely a pure templating issue.
Comment 3 Christian Ebert 2012-07-26 18:31 UTC
Well, you also get a traceback with

hg log --template '{foo|utcdate}\n'

So I'd say it's not keyword specific.

That's partly the reason why I kept the clumsy kwdemo command in the extension: Provide an ad hoc test for templating so you don't mess up your files. Not sure how I could test the validity of templates during normal background operation of the extension without a big slowdown.
Comment 4 Patrick Mézard 2012-07-27 02:51 UTC
Well, if the log call had tracebacked I would not have moved the bug to keyword category, but here:

  $ hg log --template '{foo|utcdate}\n' -l1
  hg: parse error: unknown function 'utcdate'

So maybe there is a try/except in the log code or something else, I do not know.
Comment 5 Christian Ebert 2012-07-27 04:49 UTC
You are absolutely right of course, sorry.

You get a traceback when having keyword enabled with
hg log --template '{foo|utcdate}\n'
because utcdate is one of the additional filters provided by the extension, but the extension does not catch errors with the additional filters.

Will look into it.
Comment 6 Christian Ebert 2012-07-27 05:01 UTC
To be more precise, with either utcdate or svnutcdate because do:

return util.datestr((text[0], 0), '<format>')

Something like hg log --template '{foo|shortdate}\n' returns the current date instead of a traceback - not exactly meaningful, but no traceback because the text argument is not split up.

Looks like I should do the following for utcdate and svnutcdate:

try:
    return util.datestr((text[0], 0), '<format>')
except IndexError:
    return util.datestr(text, '<format>')
Comment 7 Patrick Mézard 2012-07-27 05:03 UTC
You are right, my example was invalid. Here is a recipe for log:

  hg log --template '{foo|localdate}\n' -l1

Reassigning to mercurial itself, updating title.

And yes, some date filters do interesting things with bogus arguments.
Comment 8 Christian Ebert 2012-07-27 05:16 UTC
(In reply to comment #7)
imho keyword should still be in charge of avoiding a traceback (will send a patch shortly), but hg log --template '{foo|localdate}\n' should probably abort with something like:

parse error: invalid date

Hm, how to detect bogus dates ...
Comment 9 Christian Ebert 2012-07-27 05:31 UTC
(In reply to comment #7)
I meant to say that hg log --template '{foo|shortdate}\n' does not give a traceback, but also not a meaningful value.

So I'll wait with a patch until I see how tracebacks because of failed "date splitting" are handled in the core.
Comment 10 HG Bot 2012-10-12 17:12 UTC
Fixed by http://selenic.com/repo/hg/rev/bededd3f0735
Christian Ebert <blacktrash@gmx.net>
templatefilters: avoid traceback caused by bogus date input (issue3344)

Wrap datefilters which split date texts with util.parsedate.

We do not abort, as the bogus date must have been given by the user.

(please test the fix)