jashkenas/coffeescript

uncaughtException masked

Opened this issue · 11 comments

I cant get this scrpt to work using the latest Node and latest CoffeeScript

process.removeAllListeners 'uncaughtException'
process.on 'uncaughtException', (er) ->
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  console.log 'Unhandled exception'
  return

throw new Error("aAH")

Running coffee test.coffee just throws the normal stacktrace.

Howver the generated test.js (from coffee compile) works as planned with node test.generated.js

Same issue on Ubuntu linux server.

coffee test.coffee - No console.log, just normal strack trace output
however:
coffee -c test.coffee; node test.js - works as expected

I just posted an answer to your StackOverflow question on this:
http://stackoverflow.com/questions/6346291/nodejs-and-coffeescript-coffee-executable-not-behaving-the-same/6350100#6350100

This behavior is intentional—if the exception trickled all the way down to the process level, the coffee process itself would crash. That may seem desirable when running coffee test.coffee, but suppose that you ran coffee -w test.coffee (which runs test.coffee every time it changes); because coffee catches errors in test.coffee, you don't have to restart it every time your code generates a runtime error.

So, you should compile to JS and re-run that JS every time it changes. You could write a Cakefile to do that (the most versatile option, but requires some legwork), or just use coffee -cw test.coffee in conjunction with node-supervisor.

Why not enable this for coffee test.coffee, nobody wants to have compiled JS just sitting around in their directory just for sake of having being able to handle 'uncaughtExceptions' when they have a CS project, or going through the overhead of setting up a Cakefile. How to suggest a production deployment then? Right now for me its upstart that runs the coffee command and respawns, but it sucks that I'm not getting that valuable exception information.

Peeved, nothing personal but it just seems like the current workaround isn't a very good one unless I'm misunderstanding something. I want coffee to crash if an error happens and right now it does crash for an uncaughtException but it sucks up the valuable exception information. Plz advice.

oddly enough, sometimes it seems to allow it, i'm confused... this case is broken and I've been able to verify as well... winstonjs/winston#47

I was just bitten by this as well. Exceptions thrown from the top level don't trigger uncaughtException, but they do if I wrap the throw in a setTimeout

This causes problems with most server-side error handlers, such as Sentry.

And bugsnag.

Indeed.

We're using coffee executable on the server. We're catching most of our errors with domain. Is this still an issue we should be aware about? We wanted to use bugsnag and their docs refer to this page.

"We wanted to use bugsnag and their docs refer to this page"
still the case in 2016!

As we can see, CoffeeScript isn't for serious production deployments.