Bug 4140 - Traceback occurs if no templates are available
Summary: Traceback occurs if no templates are available
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 2.8.1
Hardware: PC Linux
: normal bug
Assignee: Bugzilla
URL:
Keywords: easy
Depends on:
Blocks:
 
Reported: 2013-12-30 21:26 UTC by Edmund Rhudy
Modified: 2014-07-19 14:17 UTC (History)
4 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 Edmund Rhudy 2013-12-30 21:26 UTC
This is kind of 1.5 bugs. When running hg log --style xxx (where xxx is a valid template name), where no templates at all are actually available, you get back an ugly traceback like the following:

** unknown exception encountered, please report by visiting
** http://mercurial.selenic.com/wiki/BugTracker
** Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
** Mercurial Distributed SCM (version 2.8.1)
** Extensions loaded: 
Traceback (most recent call last):
  File "/usr/bin/hg", line 38, in <module>
    mercurial.dispatch.run()
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 28, in run
    sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 69, in dispatch
    ret = _runcatch(req)
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 133, in _runcatch
    return _dispatch(req)
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 806, in _dispatch
    cmdpats, cmdoptions)
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 585, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 897, in _runcommand
    return checkargs()
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 868, in checkargs
    return cmdfunc()
  File "/usr/lib64/python2.6/site-packages/mercurial/dispatch.py", line 803, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/usr/lib64/python2.6/site-packages/mercurial/util.py", line 512, in check
    return func(*args, **kwargs)
  File "/usr/lib64/python2.6/site-packages/mercurial/commands.py", line 4072, in log
    displayer = cmdutil.show_changeset(ui, repo, opts, True)
  File "/usr/lib64/python2.6/site-packages/mercurial/cmdutil.py", line 970, in show_changeset
    t = changeset_templater(ui, repo, patch, opts, mapfile, buffered)
  File "/usr/lib64/python2.6/site-packages/mercurial/cmdutil.py", line 838, in __init__
    cache=defaulttempl)
  File "/usr/lib64/python2.6/site-packages/mercurial/templater.py", line 484, in __init__
    hint=_("available styles: %s") % stylelist())
  File "/usr/lib64/python2.6/site-packages/mercurial/templater.py", line 450, in stylelist
    path = templatepath()[0]
IndexError: list index out of range

(Incidentally, the reason there are no templates is because apparently bdist_rpm does not correctly generate the file manifest on this platform [CentOS 6.3] and pull in the mercurial/templates directory.)
Comment 1 Chris Jerdonek 2013-12-31 14:17 UTC
Edmund, out of curiosity, what does "hg debuginstall" give you?  It has a line about templates.
Comment 2 Simon Heimberg 2014-01-23 03:31 UTC
When I rename the directory "templates" to anything different, I get the same traceback. When I create an empty one instead, the command reports:
  abort: style 'bisect' not found
  (available styles: )
So the problem is a missing "templates" directory.

I have sent a patch fixing this traceback.



Is "setup.py bdist_rpm" does not correctly generate the file manifest on CentOS 6.3 also an open issue?


@chris
hg debuginstall reports empty brackets when there is no template directory:
  *some lines*
  checking templates ()...
  *some lines*
  no problems detected

The final line is not what I expected...

Looks like this line [1] does not raise an error:
    templater.templater(templater.templatepath("map-cmdline.default"))
This is because templatepath returns [] when not found, and templater([]) returns a valid empty templater.
You have probably found a new bug.


http://hg.intevation.org/mercurial/crew/file/2cfb720592fe/mercurial/commands.py#l2097
Comment 3 Chris Jerdonek 2014-01-23 03:52 UTC
> You have probably found a new bug.

Thanks for that additional analysis, Simon.  Would you mind filing a new issue for this while it's still fresh in your mind?  Thanks.
Comment 4 Simon Heimberg 2014-01-23 11:46 UTC
(In reply to comment #3)

reported as bug 4151
Comment 5 HG Bot 2014-01-23 18:15 UTC
Fixed by http://selenic.com/repo/hg/rev/268a5ab5c27b
Simon Heimberg <simohe@besonet.ch>
templater: selecting a style with no templates does not crash (issue4140)

Running `hg log --style compact` (or any other style) raised a traceback when
no template directory was there. Now there is a message:

Abort: style 'compact' not found
(available styles: no templates found, try `hg debuginstall` for more info)


There is no test because this would require to rename the template directory.
But this would influence other tests running in parallel. And when the test
would be aborted the wrong named directory would remain, especially a problem
when running with -l.

(please test the fix)
Comment 6 Simon Heimberg 2014-01-27 02:59 UTC
Is "setup.py bdist_rpm" does not correctly generate the file manifest on CentOS 6.3 (see in comment #0) also an open issue?
Comment 7 Matt Mackall 2014-01-31 17:50 UTC
We're not particularly concerned about whether some feature of Python's setup tools work properly unless we've exposed it as a make target.