documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

broken stack trace in forEach #95

Closed jyro2080 closed 13 years ago

jyro2080 commented 13 years ago

I recently started using underscore.js and love it a lot. I see lots of benefits from it, but I have seen one glaring caveat that I want to report.

When an exception occurs in the handler passed to the _.forEach function, the stack trace gets broken, i.e. it does go all the way to the exact cause of exception. This makes debugging the code really difficult.

Fortunately I could figure out why this happens and have a potential solution. In the forEach implementation, you have a try-catch block where you catch the exception thrown by the application handler, you check it against breaker and if it is not breaker then you throw it again. This is the statement at which the stack trace ends, and it never reaches the actual statement (which is in application code). I removed that try-catch and that fixed the stack trace.

I understand you use breaker to implement the breakloop function call. I personally don't use it, I don't know about others. I feel the broken stack trace is a more important issue than the breakloop functionality.

Can this be fixed? One possible solution is to remove that try-catch and find alternative way to implement breakLoop().

Thanks.

jashkenas commented 13 years ago

Did you post this ticket on the wrong project? Please move it to underscore, if you don't mind...

jyro2080 commented 13 years ago

I guess I did. Didn't realize it was documentcloud's other project. Sorry for that.