43

I just provided an answer with my first Stack Snippet. I choose to construct the answer in the snippet editor and debug it right within. My expectation was to use this great tool as a debugger which can ultimately run my code for the OP and show him the result in-house. However, I noticed that the line number which indicates an error in my code is not very accurate. Although it did it's job in showing the OP an executable answer, it was kind of frustrating for not being directed to the line where an error lies.

Please see the picture attachment.

enter image description here

Shouldn't this be a prioritized correction?

14
  • 5
    I was actually in the process of writing an answer about how you, as the answerer, should ensure your solution works then reread your question and saw myself agreeing with you. If it is showing you an error log, it should be shown correctly.
    – Script47
    Mar 21, 2019 at 9:40
  • 6
    FWIW, it seems to be pretty reliably off by 12 lines. Whether it's practical to intercept the messages and rewrite them I'm not certain, but it does seem a little non-trivial. Mar 21, 2019 at 9:41
  • I think they're taking from the dom line? 1liner don't mind the fiddle lost count of dom line
    – Mukyuu
    Mar 21, 2019 at 9:42
  • 8
    You will find the error being off by 6-8 lines..
    – iLuvLogix
    Mar 21, 2019 at 10:03
  • 5
    Downvoted, I don't support those perfect circles and arrows. Freehand circles RISE UP!
    – Lino
    Mar 21, 2019 at 12:27
  • 1
    @Lino - the arrow and circles are jagged, thus not perfect. Although I guess we could also request anti-aliasing to be added to screenshots.
    – VLAZ
    Mar 21, 2019 at 12:36
  • @VLAZ It is obvious that they were created using something along the lines of black magic, the jaggedness is just that they are unstable in this world, we should banish them asap and send them back where they came from
    – Lino
    Mar 21, 2019 at 12:37
  • It is MS Paint !
    – Charlie
    Mar 21, 2019 at 14:09
  • IMHO, most of the time if you are using snippets when writing an answer, they are not used to show errors, they are used to show solutions. You should debug your code in a separate environment and then copy them to a snippet when they don't have any errors. I think showing the console was more of an after-thought. Mar 22, 2019 at 0:53
  • If you open your browser's inspector, you will see that your code is served in an iframe loaded from stacksnippets.net. The code is actually one document pieced together by the HTML, CSS and JavaScript portions of your code, enclosed in <html> tag. So you could use your inspector to find which line is the actual cause of the error. Mar 22, 2019 at 0:56
  • 1
    @KodosJohnson I don't think Stack Snippet not being a debug tool nor I can get the line number via inspect will justify it showing wrong information to the answer writer.
    – Charlie
    Mar 22, 2019 at 4:56
  • 1
    I have been annoyed by this not-so-useful information from the error since I first used this. It is time that this should be "improved" so that it is easier to make use of the snippet tool.
    – holydragon
    Mar 22, 2019 at 7:50
  • @CertainPerformance what is a "userscript" ?
    – Charlie
    Mar 22, 2019 at 9:15
  • 1
    See wiki and even a dedicated site for SE scripts :). Basically, custom client-side Javascript injected into the page Mar 22, 2019 at 9:17

1 Answer 1

7

I sympathize.

When snippets were initially launched, we (the meta.SO community) recognized that this may be confusing. We suggested loading the script as an external or data URI source. That suggestion was ultimately declined and, to be honest, snippets haven't seen much development since then (related).

I'd argue that the error logging is still useful (not great) as is. If you follow the browser debugging trail you'll find what you're looking for.

Still, particularly for javascript-only snippets (e.g.: nodejs), it'd be nice to get those scripts out of the document. We've discussed the possibility of offering a run in webworker option for javascript-only snippets to further disentangle them from the page context. There's not much hope of that, though; SE is (apparently) understaffed and focused on other things.

7
  • 3
    Technically right things are only useful when they are practically right.
    – Charlie
    Mar 22, 2019 at 18:15
  • 2
    Sorry you're dissatisfied.
    – canon
    Mar 22, 2019 at 18:45
  • No problem. I can really do with what it is today. But I'm sure we all wish for an improvement to make it even more useful for the community. Thanks!
    – Charlie
    Mar 22, 2019 at 18:50
  • I'm curious to know why loading the script as an external source was declined? Also do you work for SE? It's not clear from your profile. Mar 27, 2019 at 19:13
  • @KodosJohnson Apologies, I don't recall the rationale. Nor do I work for SE. I created a javascript resource to facilitate light-weight console visualization in my SO answers long before SE had implemented anything official. They pretty much adopted my script, forking it for their own use. My script has since evolved in a number of ways (with plans for webworker javascript-only support) but SE is on its own path.
    – canon
    Mar 27, 2019 at 19:36
  • oh ok thanks for your contribution. I was wondering if it would be possible to keep track of the line numbers where the the different sections (HTML,CSS,JS) start and end, and then when an error occurs, check if it is within one of the sections, then calculate the "real" line number within the input box. Then override the error message to show something like "line xx of JavaScript". Mar 27, 2019 at 19:50

You must log in to answer this question.

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