requireDir
requireDir copied to clipboard
How to handle errors in required file?
Some of my files have erroneous code in them. How can I catch the exceptions thrown by these during the require? Currently I can only try-catch the whole require-dir, not on a file by file basis.
We could add an onError option that would wrap https://github.com/aseemk/requireDir/blob/master/index.js#L128 in a try/catch - why do you need to catch it per-file?
Yes that is basically what I have done for now. I have a case where I have some (or a lot) of files in the directory I'm requiring that now throw errors due to changes I've made elsewhere, but I still want to test fixing some of them to see if my changes work for those, then update the rest of the erroring files, but to catch those errors for the time being so they don't crash the app, until I fix the rest of them.
IK I can just require the individual files that I'm testing the fixes for, but this would just be a nice feature.
It seems like a fine option to add and should only add a few lines of code - feel free to send a PR that includes docs + tests.