minirst formatter chokes on bad width (was Re: Crash on Mercurial book production)

Matt Mackall mpm at selenic.com
Thu Sep 3 11:17:16 CDT 2009


On Thu, 2009-09-03 at 00:00 +0200, Guido Ostkamp wrote:
> Hi,
> 
> the following article was originally sent to Bryan O' Sullivan, but as I 
> got no response, I'm reposting it here, maybe someone else can help:
> 
> I am running into a problem with the production of the Mercurial book. All 
> the code examples which contains a 'help' command cause a Mercurial crash.
> 
> I tried to investigate this a bit and found that in 
> en/examples/run-example there is code that forks with pty.fork() before 
> exec'ing some bash shell.
> 
> When Mercurial gets e.g. the 'hg help init' command, some mechanism gets 
> involved which tries to split the lines accurately according to the number 
> of columns of the terminal. This code uses Mercurial 'util.py' function 
> termwidth().
> 
> By introducing some debug lines I figured that on my system the COLUMNS 
> variable doesn't seem to be set any longer when the code is called through 
> the 'run-example' sequence.
> 
> Mercurial then crashes as shown below.
> 
> >From my standard shell prompt 'hg help init' etc. works without problems 
> and COLUMNS variable is set correctly and exported. For the reference, I'm 
> on Mercurial version 37042e8b3b34, Python 2.6.2 on OpenSuSE 10.3 Linux.
> 
> Are you running into the same problem?
> 
> Is it possible to internally set the terminal width to something suitable 
> for book production after the fork()?
> 
> Best regards
> 
> Guido
> 
> ** unknown exception encountered, details follow
> ** report bug details to http://mercurial.selenic.com/bts/
> ** or mercurial at selenic.com
> ** Mercurial Distributed SCM (version )
> ** Extensions loaded:
> Traceback (most recent call last):
>     File "/usr/local/bin/hg", line 27, in <module>
>       mercurial.dispatch.run()
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 16, in run
>       sys.exit(dispatch(sys.argv[1:]))
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 27, in dispatch
>       return _runcatch(u, args)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 43, in _runcatch
>       return _dispatch(ui, args)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 449, in _dispatch
>       return runcommand(lui, repo, cmd, fullargs, ui, options, d)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 317, in runcommand
>       ret = _runcommand(ui, options, cmd, d)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 501, in _runcommand
>       return checkargs()
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 454, in checkargs
>       return cmdfunc()
>     File "/usr/local/lib/python2.6/site-packages/mercurial/dispatch.py", 
> line 448, in <lambda>
>       d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/util.py", line 
> 402, in check
>       return func(*args, **kwargs)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/commands.py", 
> line 1579, in help_
>       f(name)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/commands.py", 
> line 1479, in helpcmd
>       ui.write("\n%s\n" % minirst.format(doc, textwidth))
>     File "/usr/local/lib/python2.6/site-packages/mercurial/minirst.py", line 
> 321, in format
>       return '\n'.join(formatblock(b, width) for b in blocks)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/minirst.py", line 
> 321, in <genexpr>
>       return '\n'.join(formatblock(b, width) for b in blocks)
>     File "/usr/local/lib/python2.6/site-packages/mercurial/minirst.py", line 
> 308, in formatblock
>       subsequent_indent=subindent)
>     File "/usr/local/lib/python2.6/textwrap.py", line 358, in fill
>       return w.fill(text)
>     File "/usr/local/lib/python2.6/textwrap.py", line 330, in fill
>       return "\n".join(self.wrap(text))
>     File "/usr/local/lib/python2.6/textwrap.py", line 321, in wrap
>       return self._wrap_chunks(chunks)
>     File "/usr/local/lib/python2.6/textwrap.py", line 250, in _wrap_chunks
>       raise ValueError("invalid width %r (must be > 0)" % self.width)
> ValueError: invalid width -2 (must be > 0)

Let's try putting a useful subject on this and see if anyone pays
attention.

-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial-devel mailing list