Skip to content

Commit cccf3dc

Browse files
committed
Fix error message: output port at which port finder failed to find an open port
Allows promise and callback versions of the api to both provide the port at which they failed at in their error message. This could also be done by changing the promise resolver to take the ports array but that seems superfluous.
1 parent dccf68d commit cccf3dc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/portfinder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ internals.getPort = function (options, callback) {
198198
return callback(null, openPorts[0]);
199199
}
200200
else {
201-
const msg = 'No open ports found in between '+ options.startPort + ' and ' + options.stopPort;
201+
const msg = `Searching for an open port failed at port ${openPorts[0]}.`;
202202
return callback(Error(msg));
203203
}
204204
} else {

test/port-finder-multiple.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ describe('with 5 existing servers', function () {
5858
})
5959
.catch(function (err) {
6060
expect(err).not.toBeNull();
61-
expect(err.message).toEqual('No open ports found in between 32768 and 32774');
61+
expect(err.message).toEqual('Searching for an open port failed at port 32775.');
6262
done();
6363
});
6464
} else {
6565
method(3, { stopPort: 32774 }, function (err, ports) {
6666
expect(err).not.toBeNull();
67-
expect(err.message).toEqual('No open ports found in between 32768 and 32774');
68-
expect(ports).toEqual([32773, 32774, undefined]);
67+
expect(err.message).toEqual('Searching for an open port failed at port 32775.');
68+
expect(ports).toEqual([32773, 32774, undefined]); // Failed at port 32775
6969
done();
7070
});
7171
}

test/port-finder.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ describe('with 5 existing servers', function () {
8282
})
8383
.catch(function (err) {
8484
expect(err).not.toBeNull();
85-
expect(err.message).toEqual('No open ports found in between 32768 and 32772');
85+
expect(err.message).toEqual('Searching for an open port failed at port 32773.');
8686
done();
8787
});
8888
} else {
8989
method({ stopPort: 32772 }, function (err, port) {
9090
expect(err).not.toBeNull();
91-
expect(err.message).toEqual('No open ports found in between 32768 and 32772');
91+
expect(err.message).toEqual('Searching for an open port failed at port 32773.');
9292
expect(port).toBeUndefined();
9393
done();
9494
});

0 commit comments

Comments
 (0)