2

I tried to post a question on SO.

The preview of the post is:

Output

And my code segments are:

Code 2

Code 3

I found everything correct, but SO refused to post the question as asked me indent the code by four spaces (even I did that).

This is so frustrating and I spent nearly an hour to resolve the formatting, but I couldn't.

14
  • 3
    You can use ``` (triple `) even around output and error messages. Easier to handle than manually ensuring 4 leading spaces each line.
    – qrsngky
    Mar 22 at 11:42
  • 2
    Is this using the new wizard? or the old one. Looks like the old one,
    – Kevin B
    Mar 22 at 17:47
  • 3
    I assume you have "[1]:link, [2]:link, [3]:link", separated by one line break each at the bottom. Try adding an additional line between each. If that doesn't work, add line breaks in the text where you have the links ("[here][1]").
    – Laurel
    Mar 22 at 18:45
  • 4
    @qrsngky Please don't recommend users put code fences around error messages. They should put them in block quotes instead and only use single backticks around parts of the error message that are code.
    – TylerH
    Mar 22 at 20:18
  • 1
    Can you include a screenshot of the entire body of the input box(es) showing you the error message? Or include it here in your meta post? It will be difficult to
    – TylerH
    Mar 22 at 20:21
  • 7
    @TylerH strongly disagree WRT formatting error messages. There is extremely well established precedent for formatting them like code, which makes them look like they do in the terminal. There are several environments that attempt to take advantage of the entire error message being monospaced - in particular, Python 3.10 and up will show code in a traceback and attempt to highlight part of the line by "underlining" it with ^ symbols on the next line. Before that, it would still use a single ^ to try to "point at" a spot in the line. It also indents lines in a stack trace. Mar 22 at 22:01
  • 1
    Also WRT Python, it is very common to show examples as a REPL session, in which case an exception might be intermingled with code, and lines of code may be prefixed with >>> and ... . Trying to reformat that according to your proposal would be a lot of work for, in my view, a net loss in clarity. Mar 22 at 22:03
  • 1
    @KarlKnechtel Error messages, in general, are not code; they are prose, so they should not be tagged with code backticks. I and many others have been revising posts and passing guidance this way for years on the site. In some cases there are error messages that do contain code or that are only ever shown in a code environment; as my comment above mentioned, such cases can and should include code backticks around them.
    – TylerH
    Mar 22 at 22:05
  • 4
    I've lost count of the times that OP tried to format a Python stack trace as a block quote and made an unreadable mess out of it. When this happens, it is tedious-to-nearly-impossible to recover the intended appearance. Mar 22 at 22:05
  • 1
    In response to your specific example, stack traces (in any language) are usually an exception to the "use block quote formatting for error messages". But the vast majority of error messages are not stack traces. In fact I would argue that stack traces are not actually error messages, but more akin to logs.
    – TylerH
    Mar 22 at 22:07
  • 1
    "In some cases there are error messages that do contain code or that are only ever shown in a code environment" - Unless the error was in a modal dialog created by an IDE or a JavaScript alert, I fail to see how that ever isn't the case. Mar 22 at 22:07
  • 3
    "But the vast majority of error messages are not stack traces. In fact I would argue that stack traces are not actually error messages, but more akin to logs." I genuinely can't even imagine an example of what you have in mind. But even when the problem actually is being exhibited with an unexpected log message, rather than an error per se - it is still common for log messages to be deliberately formatted with the assumption that they will be displayed in a monospace font, i.e., using fixed-width "columns". Mar 22 at 22:07
  • 1
    I believe it's due to the "my file is [here]" links. I think you've typed single line breaks between those lines, which aren't rendered in the rendered post, and that combined with the brackets is causing that part to be recognized as code. Try putting a second line break (i.e., an empty line) between each of those links and see if that works.
    – gparyani
    Mar 23 at 0:34
  • 1
    @KarlKnechtel Perhaps both your and TylerH's views on these matters are colored a wee bit by the development environments you work with daily? Python apparently is geared toward being compiled in an environment using a monospaced font. So, if you are answering questions in [python], by all means, use code formatting instead of blockquote (or use both [e.g., > ``` ]) In general, however, the expectation is that error messages are in blockquotes (as you are quoting the system reporting the error). Mar 23 at 18:24

0

You must log in to answer this question.

Browse other questions tagged .