Skip to content

Commit 6da9d39

Browse files
committed
v5.1.0 / 2020-07-28
1 parent 624665a commit 6da9d39

12 files changed

+42
-22
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# node-dev
22

3+
## v5.1.0 / 2020-07-28
4+
5+
- [wrap.js] Improve uncaughtException handling to turn non-errors into errors (Fixes #231)
6+
- [ipc.js] Declare `NODE_DEV` as a variable
7+
- [ipc.js] Inline single line function only used twice
8+
- [tests] Filenames should be snake-case
9+
310
## v5.0.0 / 2020-07-08
411

512
- Remove `--all-deps` and `--no-deps` CLI options, use `--deps=-1` or `--deps=0` respectively

lib/ipc.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
/**
2-
* Checks if the given message is an internal node-dev message.
3-
*/
4-
function isNodeDevMessage(m) {
5-
return m.cmd === 'NODE_DEV';
6-
}
1+
const NODE_DEV = 'NODE_DEV';
72

83
/**
94
* Sends a message to the given process.
105
*/
116
exports.send = function (m, dest) {
12-
m.cmd = 'NODE_DEV';
7+
m.cmd = NODE_DEV;
138
if (!dest) dest = process;
149
if (dest.send) dest.send(m);
1510
};
1611

1712
exports.on = function (proc, type, cb) {
1813
function handleMessage(m) {
19-
if (isNodeDevMessage(m) && type in m) cb(m);
14+
if (m.cmd === NODE_DEV && type in m) cb(m);
2015
}
2116
proc.on('internalMessage', handleMessage);
2217
proc.on('message', handleMessage);
@@ -25,7 +20,7 @@ exports.on = function (proc, type, cb) {
2520
exports.relay = function (src, dest) {
2621
if (!dest) dest = process;
2722
function relayMessage(m) {
28-
if (isNodeDevMessage(m)) dest.send(m);
23+
if (m.cmd === NODE_DEV) dest.send(m);
2924
}
3025
src.on('internalMessage', relayMessage);
3126
src.on('message', relayMessage);

lib/wrap.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ if (fork) {
3535

3636
// Error handler that displays a notification and logs the stack to stderr:
3737
process.on('uncaughtException', function (err) {
38-
console.error(err.stack || err);
38+
// Sometimes uncaught exceptions are not errors
39+
const { message, name, stack } = err instanceof Error ? err : new Error(`uncaughtException ${err}`);
40+
41+
console.error(stack);
42+
3943
// If there's a custom uncaughtException handler expect it to terminate
4044
// the process.
41-
const hasCustomHandler = process.listeners('uncaughtException').length > 1;
42-
ipc.send({
43-
error: err.name || 'Error',
44-
message: err.message,
45-
willTerminate: hasCustomHandler
46-
});
45+
const willTerminate = process.listeners('uncaughtException').length > 1;
46+
47+
ipc.send({ error: name, message, willTerminate });
4748
});
4849

4950
// Hook into require() and notify the parent process about required files

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-dev",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "Restarts your app when files are modified",
55
"keywords": [
66
"restart",

test/fixture/.node-dev.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"notify": false,
33
"ignore": [
4-
"./ignoredModule.js"
4+
"./ignored-module.js"
55
],
66
"extensions": {
77
"coffee": "coffeescript/register",

test/fixture/error-null.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require('./message');
2+
3+
// eslint-disable-next-line no-throw-literal
4+
throw null;
File renamed without changes.
File renamed without changes.

test/fixture/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var http = require('http');
22
var message = require('./message');
33

44
// Changes to this module should not cause a server restart:
5-
require('./ignoredModule');
5+
require('./ignored-module');
66

77
var server = http.createServer(function (req, res) {
88
res.writeHead(200, { 'Content-Type': 'text/plain' });

test/spawn.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,28 @@ tap.test('should handle errors', function (t) {
4040
});
4141
});
4242

43+
tap.test('should handle null errors', function (t) {
44+
spawn('error-null.js', function (out) {
45+
if (out.match(/ERROR/)) {
46+
touchFile();
47+
return function (out2) {
48+
if (out2.match(/Restarting/)) {
49+
return { exit: t.end.bind(t) };
50+
}
51+
};
52+
}
53+
});
54+
});
55+
4356
tap.test('should watch if no such module', function (t) {
44-
spawn('noSuchModule.js', function (out) {
57+
spawn('no-such-module.js', function (out) {
4558
t.like(out, /ERROR/);
4659
return { exit: t.end.bind(t) };
4760
});
4861
});
4962

5063
tap.test('should run async code un uncaughtException handlers', function (t) {
51-
spawn('uncaughtExceptionHandler.js', function (out) {
64+
spawn('uncaught-exception-handler.js', function (out) {
5265
if (out.match(/ERROR/)) {
5366
return function (out2) {
5467
if (out2.match(/async \[?ReferenceError/)) {
@@ -60,7 +73,7 @@ tap.test('should run async code un uncaughtException handlers', function (t) {
6073
});
6174

6275
tap.test('should ignore caught errors', function (t) {
63-
spawn('catchNoSuchModule.js', function (out) {
76+
spawn('catch-no-such-module.js', function (out) {
6477
t.like(out, /Caught/);
6578
return { exit: t.end.bind(t) };
6679
});

0 commit comments

Comments
 (0)