On 2011-08-31, Aivar wrote:
> Hi!

> In some cases, when I make syntax mistake in reST source and when
> there is a non-ascii character around, I get stacktrace instead of
> helpful message telling me where is the mistake. It's quite hard to
> track down such mistakes.

> One example is when I forget empty line after directive, for example:

> .. sourcecode:: python
>     for i in range(a,b):
>         # käsud


> Another example: too short section underline:

>       Lisanäited
>       ------

> I'm not sure if this is problem in Sphinx or in docutils,

Docutils seems to work fine. After changing "sourcecode" to "code", I get
the following output from docutils SVN version::

  /tmp/umlaut.rst:3: (ERROR/3) Error in "code" directive:
  maximum 1 argument(s) allowed, 7 supplied.
  
  .. code:: python
      for i in range(a,b):
          # käsud
  
  
  /tmp/umlaut.rst:11: (WARNING/2) Title underline too short.
  
  Lisanäited
  ------
  /tmp/umlaut.rst:11: (SEVERE/4) Unexpected section title.
  
  Lisanäited
  ------
  Exiting due to level-4 (SEVERE) system message.

>  can't tell > from the stacktrace:


> Warning, treated as error:
> Traceback (most recent call last):
>   File "c:\python27\scripts\sphinx-build-script.py", line 8, in
><module>
>     load_entry_point('Sphinx==1.0.7', 'console_scripts', 'sphinx-
> build')()
>   File "c:\python27\lib\site-packages\sphinx-1.0.7-py2.7.egg\sphinx
> \__init__.py"
> , line 67, in main
>     return cmdline.main(argv)
>   File "c:\python27\lib\site-packages\sphinx-1.0.7-py2.7.egg\sphinx
> \cmdline.py",
>  line 212, in main
>     print >>error, err
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
> position 202
>: ordinal not in range(128)

You might try to change line 212, in
c:\python27\lib\site-packages\sphinx-1.0.7-py2.7.egg\sphinx\cmdline.py

from 

>     print >>error, err

to 

>     print >>error, err.encode("utf-8")

or something more secure like

>     print >>error, err.encode("ascii", "backslashreplace")

(in case the output stream does not know how to handle utf-8).

The idea is explained and used in more detail in Docutils'
error_reporting sub-module. See the diffs of `revision 7037`__
http://svn.berlios.de/viewvc/docutils?view=revision&revision=7037 for the
changes made in Docutils to overcome Python's error-reporting-encoding
problems.

Günter

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to