26

When I have a question that displays an error message from somewhere, is it better to place that error message inside a code markup block or a quote markup block?

It seems like more people are doing it with code markup blocks, but that doesn't really make sense as error messages are not code; rather, they are quotes from whatever entity generated the message.

3
  • 1
    Note that in a quote you'd need to manually escape any < (and >) character.
    – Arjan
    Jan 26, 2013 at 15:16
  • 2
    and # @Arjan; you get random headings otherwise. Jan 26, 2013 at 15:23
  • 2
    I'm surprised there is no official recommendation for this.
    – BBaysinger
    Apr 6, 2018 at 20:24

3 Answers 3

22

It has nothing to do with whether the error is code or not. You should use the option which renders the error message in the most readable manner. For me, this has normally been as quoted text rather than code but that is not true for every situation.

For instance, if we take this Java exception marked up as code it looks like this:

Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at Intro.<init>(Intro.java:15)
    at Intro.main(Intro.java:58)    

and as a quote like this:

Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.(Unknown Source) at Intro.(Intro.java:15) at Intro.main(Intro.java:58)

The quote does not look good.

However, looking at this Oracle error marked up as code

ERROR at line 1: ORA-01400: cannot insert NULL into ("SCHEMA"."TMP_BEN_TEST"."A") ORA-02063: preceding line from DB1 ORA-06512: at line 18

It is more difficult to read; far better as a quote:

ERROR at line 1: ORA-01400: cannot insert NULL into ("SCHEMA"."TMP_BEN_TEST"."A") ORA-02063: preceding line from DB1 ORA-06512: at line 18

3
  • 2
    As an aside: note the different rendering on mobile (code blocks never show scrollbars: they are not limited in height, and have no horizontal scrollbars but wrap text instead). But long stack traces should be avoided anyhow.
    – Arjan
    Jan 26, 2013 at 15:34
  • 2
    I also wonder if screen readers might somehow interpret code blocks differently from quotes?
    – Arjan
    Jan 26, 2013 at 15:42
  • I've been trying to find a particularly egregious example I remember of the long stack trace art (about 150 lines long and that was the entire question) but I have a feeling I only saw it whilst voting to delete... I honestly have no idea how a screen reader might see it. You could ask the question :-). Jan 26, 2013 at 15:48
3

In my opinion stacktraces look very readable when they are formatted using python as a language something like -

```python
your ugly error

```

This will render like - enter image description here

2
  • 2
    Can you explain why you think that looks good? I think it looks awful, with the random red and blue highlights on words. Jan 27, 2023 at 13:31
  • It is a personal preference.
    – markroxor
    Jan 28, 2023 at 14:02
2

I'd put it in a code block, but use none as the language to avoid funky syntax highlighting that usually just doesn't make sense:

<!-- language: none -->

    This is the error that isn't code but isn't a quotation

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .