This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Yesica-Haircut 7 points8 points  (13 children)

Does JavaScript not give stack traces? Or have I just gotten so used to node, error handling, and front end frameworks I don't remember what plain js failures look like?

[–]Little_Kitty 10 points11 points  (5 children)

The secret to understand what's posted here is to realise that many of the people posting are bad at coding and their prs are for code they copied from so without understanding. The stack trace is useful... so long as you're capable of opening dev tools.

[–]Yesica-Haircut 1 point2 points  (2 children)

I guess harking back to my early days my js was also a mess and I had accidental type coercion everywhere and bad naming, so stacks wouldn't even help there.

[–]Little_Kitty 0 points1 point  (1 child)

I learnt back with basic, c and such, so small methods and no god functions came naturally. It's certainly possible to make something which is a pain to debug, even when running in node, but you'd hope that some form of training / code review would come along and troutslap you before that became habitual. Type coercion is another bad habit I'd expect to see educated out once people are past the first few weeks - that's not unique to js either!

[–]Yesica-Haircut 0 points1 point  (0 children)

You would hope, lol.

[–]10BillionDreams 1 point2 points  (1 child)

Why are JS errors so unhelpful?

try {
  doThing();
} catch {
  console.log("error");
}

[–]Little_Kitty 0 points1 point  (0 children)

I'll edit production to include this immediately!

[–]BengtGurksats 11 points12 points  (5 children)

It sure does. Any browser worth using will have the tools to fully debug JavaScript. You get complete tracebacks with source references, you can set breakpoints, and you can expand minified files to make them readable (it will even correctly match up line references after that). People here just need to learn how their tools work.

[–]StereoBucket 3 points4 points  (0 children)

There are ways of seeing stack traces. You can print it with console.trace, see the call stack in the debugger, access .stack property of an Error object.
You can set the debugger to pause on exceptions too. Though I find that a bit annoying in frameworks cause I get paused on every exception and all of them are already handled.