Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle errors in required file? #63

Open
Arcanorum opened this issue Aug 17, 2020 · 3 comments
Open

How to handle errors in required file? #63

Arcanorum opened this issue Aug 17, 2020 · 3 comments

Comments

@Arcanorum
Copy link

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.

@yocontra
Copy link
Collaborator

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?

@Arcanorum
Copy link
Author

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.

@yocontra
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants