#Errors and error handling in typescript

13 messages · Page 1 of 1 (latest)

hard crag
#

Been writing typescript in Vue3 for about 5 months. Been a long time BEAMer writing Erlang, Elixir, LFE etc for over 20 years now and really BEAM-brained and this has given me a huge blind spot which I have just stumbled on with regard to errors.

So in the BEAM you just crash on error "Let it crash" and all crashes/errors are logged and every process is part of a supervision process that knows how to restart it and, and, and crashing is normal, you write fragile code (like after 7 years of writing Erlang full time I checked and had written 7 try/catches for managing external inputs). Crash, crash, crash your code will let you know, programme the happy path and only the happy path...

So blah-blah, writing typescript and I just discovered that this code path that is run every 5 minutes calls a function that JUST DOESN'T EXIST. (Its to do with JWT expiry, so the behavior was low level nagging but not terminal for the last few months, and I thought it was something else).

So my questions are:

  • what happens to errors in Typescript? Why don't I see them in DevTools?
  • what is the best practice for catching and logging them? Try/Catch everywhere?
hard crag
#

Maybe its not that bad, its 3 weeks since I introduced that bug, but still

coral jewel
#

@hard crag You should see errors in the dev tools, if you're not then I'd suspect there's somewhere in your code that's doing the equivalent of catch(e) { /* ignore */ }

hard crag
#

That makes a lot of sense, my big blind spot is covered up by another smaller blind spot 😉

#

I have a log-and-ignore strategy and I guess having a logDebug where I outghta have a logError or logWarning is a distinct possibility

coral jewel
#

It's possible whatever framework you're working with has some error handling built into it, though i'd be surprised if it were just silently ignoring errors

hard crag
#

Vue3

#

pretty good at borking on me, I give it practice enought...

coral jewel
#

Yeah, I don't know Vue personally, but might be worth checking how it handles thrown errors inside its stuff.

#

But yeah, personally I use very little try/catch and mostly let things blow up.

hard crag
#

oh it crashes merrily, almost like being back home in my beloved BEAM 😉

#

Ta muchos, not so paniced now

#

!resolved