Skip to content

Commit

Permalink
fix: throw in (set|get)ters when constant == null
Browse files Browse the repository at this point in the history
  • Loading branch information
hertzg committed Nov 7, 2020
1 parent afd62f3 commit b5f1ce4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ module.exports.getKeepAliveProbes = function getKeepAliveProbes(socket) {
/**
* Sets the TCP_USER_TIMEOUT value for specified socket.
*
* Note: The msec will be rounded towards the closest integer
* Notes:
* * This method is only supported on `linux`, will throw on `darwin` and `freebsd`.
* * The msec will be rounded towards the closest integer.
*
*
* @since v1.4.0
* @param {Net.Socket} socket to set the value for
Expand All @@ -229,19 +232,21 @@ module.exports.getKeepAliveProbes = function getKeepAliveProbes(socket) {
* NetKeepAlive.setUserTimeout(s, 30000)
*
* @throws {AssertionError} setUserTimeout requires two arguments
* @throws {AssertionError} setUserTimeout called on unsupported platform
* @throws {AssertionError} setUserTimeout expects an instance of socket as its first argument
* @throws {AssertionError} setUserTimeout requires msec to be a Number
* @throws {ErrnoException|Error} Unexpected error
*/
module.exports.setUserTimeout = function setUserTimeout(
socket,
msecs
) {
module.exports.setUserTimeout = function setUserTimeout(socket, msecs) {
Assert.strictEqual(
arguments.length,
2,
'setUserTimeout requires two arguments'
)
Assert(
Constants.TCP_USER_TIMEOUT != null,
'setUserTimeout called on unsupported platform'
)
Assert(
_isSocket(socket),
'setUserTimeout expects an instance of socket as its first argument'
Expand Down Expand Up @@ -269,6 +274,8 @@ module.exports.setUserTimeout = function setUserTimeout(
/**
* Returns the TCP_USER_TIMEOUT value for specified socket.
*
* Note: This method is only supported on `linux`, will throw on `darwin` and `freebsd`.
*
* @since v1.4.0
* @param {Net.Socket} socket to check the value for
*
Expand All @@ -278,6 +285,7 @@ module.exports.setUserTimeout = function setUserTimeout(
* NetKeepAlive.getUserTimeout(s) // returns 30000 based on setter example
*
* @throws {AssertionError} getUserTimeout requires one arguments
* @throws {AssertionError} getUserTimeout called on unsupported platform
* @throws {AssertionError} getUserTimeout expects an instance of socket as its first argument
* @throws {ErrnoException|Error} Unexpected error
*/
Expand All @@ -287,6 +295,10 @@ module.exports.getUserTimeout = function getUserTimeout(socket) {
1,
'getUserTimeout requires one arguments'
)
Assert(
Constants.TCP_USER_TIMEOUT != null,
'getUserTimeout called on unsupported platform'
)
Assert(
_isSocket(socket),
'getUserTimeout expects an instance of socket as its first argument'
Expand Down

0 comments on commit b5f1ce4

Please sign in to comment.