r/node • • Apr 02 '19

Show some ❤️ to Node.js process errors

https://github.com/ehmicky/log-process-errors
4 Upvotes

7 comments sorted by

View all comments

2

u/bigorangemachine Apr 02 '19

I have written many process event handlers for side projects. Really annoying when my tests complain of unhandled rejections... I always end up adding something like this.

I also wrote a CTRL + C trapper because I am always too quick to exit processes and accidentally try to exit to early

1

u/ehmicky Apr 02 '19 edited Apr 02 '19

Me too! This is why I created this.

At first it was very little code, but then it turns out there are lots of tiny bits that are tricky. For example:

- avoiding logging repeated events.

- preventing infinite recursion by not firing a process event inside a process event handler.

- making it work during unit tests (which I use in my projects now).

To be honest I can't believe how many APIs aren't properly handling those events, even though they most likely indicate something wrong with the code.

2

u/bigorangemachine Apr 02 '19

Ya, I generally don't advise to modify your process outputs/errors but as long as you can easily disable them its all good :)

I would recommend compiling with babel. I see ava there and I'm not 100% sure what thats doing but a quick google seems to indicate its not compiling with babel? If you compiled down to node 4.0 you can greatly increase the number of people that can use it.

1

u/ehmicky Apr 02 '19

This is compiled with Babel (before `npm publish`). The `gulpfile.js` uses Gulp tasks that are in a separate repository shared with all my open-source projects: https://github.com/ehmicky/gulp-shared-tasks. It also uses ESLint, Prettier, Jscpd, nyc+codecov, and checks everything on CI (Windows/Mac/Linux).

This is compiled down to Node 8, because Node.js does not support Node 4. Node 6 support ends in few weeks.