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

Günter Milde via Docutils-develop <[email protected]> Wed, 19 Feb 2025 18:22:38 -0000
Newsgroups gmane.text.docutils.devel
Message-ID </p/docutils/patches/208/41fec64aaee43cd3b43e49f3d22fb1a2ab6d9685.patches@docutils.p.sourceforge.net>
- **status**: pending-remind --> closed-rejected
- **Comment**:

Thank you for the feedback and patch.

Hower, IMO, the problem is better solved in the sphinx-argparse-cli extension.



---

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

**Status:** closed-rejected
**Group:** None
**Created:** Wed Jan 17, 2024 07:29 PM UTC by Colin Marquardt
**Last Updated:** Mon Apr 15, 2024 12:33 PM 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.