[docutils:patches] #208 On parse error, print text block when src=None

Günter Milde via Docutils-develop <[email protected]>
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/patches/208/5cacd054cf04b78c873c452a79ca0a0d61a761c1.patches@docutils.p.sourceforge.net>
- **status**: open --> pending-remind



---

**[patches:#208] On parse error, print text block when src=None**

**Status:** pending-remind
**Group:** None
**Created:** Wed Jan 17, 2024 07:29 PM UTC by Colin Marquardt
**Last Updated:** Mon Feb 05, 2024 11:25 AM UTC
**Owner:** nobody


I am using https://github.com/tox-dev/sphinx-argparse-cli to document my Python app's command line options.
When I have a formatting error in the help text of such a command line option, I am getting an error like the following:

None:5: ERROR: Unexpected indentation

 With the patch below, I have a much better chance to find the offending piece of code by printing some context, like so:

None:5: ERROR: Unexpected indentation near text:
Foo
Bar
 
~~~

--- docutils/parsers/rst/states_orig.py     2024-01-04 14:46:37.402565000 +0100
+++ docutils/parsers/rst/states.py          2024-01-17 13:48:00.991420000 +0100
@@ -2793,8 +2793,16 @@
             block = self.state_machine.get_text_block(flush_left=True)
         except statemachine.UnexpectedIndentationError as err:
             block, src, srcline = err.args
-            msg = self.reporter.error('Unexpected indentation.',
-                                      source=src, line=srcline)
+            if src is None:
+                msg = self.reporter.error(
+                    'Unexpected indentation near text:\n' +
+                    ' '.join(list(context)) +
+                    '\n' +
+                    ' '.join(list(block)),
+                    source=src, line=srcline)
+            else:
+                msg = self.reporter.error('Unexpected indentation',
+                                          source=src, line=srcline)
         lines = context + list(block)
         paragraph, literalnext = self.paragraph(lines, startline)
         self.parent += paragraph
~~~



---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/docutils/patches/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/patches/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.