53

In StackOverflow, I often see users posting long errors messages (or Exception stacktraces). Is there any correct way of formatting this kind of thing on StackExchange sites ?

Code ? :

[ERROR] Line 38: No source code is available for type com.google.gwt.visualization.client.test; did you forget to inherit a required module?

Blockquote ? :

[ERROR] Line 38: No source code is available for type com.google.gwt.visualization.client.test; did you forget to inherit a required module?

Plain ? :

[ERROR] Line 38: No source code is available for type com.google.gwt.visualization.client.test; did you forget to inherit a required module?

4
  • 7
    Code, with <!-- language: lang-none --> to turn syntax highlighting off, I'd say. Jul 27, 2012 at 11:23
  • @DanielFischer, I asked myself if that would be the correct way. However, the language tag specifies software code right ? IMHO, from a semantic point of view, that's not correct for stacktraces. Jul 27, 2012 at 11:28
  • 1
    Well, you need to keep the linebreaks, or the message becomes unreadable. Thus a blockquote is wrong, as is plain. You could try <pre>, but directly using HTML tags is, as far as I know, frowned upon somewhat. Jul 27, 2012 at 11:33
  • 1
    @DanielFischer, you should write an answer, rather than commenting. Your line break argument is valid, and therefore I would like to mark this as an answer Jul 27, 2012 at 11:47

1 Answer 1

46

To keep the stack traces/error messages readable, line breaks need to be preserved, since they have meaning in such messages.

Although it is possible to insert line breaks into plain text or blockquotes by ending each line with two spaces, that is a lot of work for longer traces.

A further point is that - in my opinion - a monospaced font makes such messages more readable than a proportional font.

Thus my preferred solution is a code block, with syntax highlighting turned off by a <!-- language: lang-none --> hint before the code block.

4
  • 1
    Using <!-- language: lang-none --> turns off highlighting, but it gets displayed. I would expect it is hidden.
    – dzieciou
    Jan 22, 2013 at 15:29
  • 5
    @dzieciou I never saw it getting displayed. Perhaps you put it in the wrong place? The HTML comment should not be indented, and separated from the code block it applies to by a blank line. Jan 22, 2013 at 15:35
  • If you are doing this on your own site and using highlightjs then set class="no-highlight". Apr 11, 2014 at 1:04
  • 1
    Besides, sometimes compilers use correctly-aligned ^~~~~ to point to a specific part in the above line, which can only be correctly displayed with a monospace font.
    – user202729
    Sep 2, 2018 at 6:46

You must log in to answer this question.

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