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

timers: Migrate to use internal/errors #14659

Closed
wants to merge 1 commit into from

Conversation

@starkwang
Copy link
Contributor

@starkwang starkwang commented Aug 7, 2017

ref: #11273

Migrate the timers module to use internal/errors. And some tests are added for timers.enroll().

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

timers, test, errors

lib/timers.js Outdated
}

if (msecs < 0 || !isFinite(msecs)) {
throw new RangeError('"msecs" argument must be ' +
'a non-negative finite number');
throw new errors.RangeError('ERR_INVALID_OPT_VALUE', 'msecs', msecs);

This comment has been minimized.

@tniessen

tniessen Aug 7, 2017
Member

This does not contain information about the allowed range anymore.

This comment has been minimized.

@refack

refack Aug 7, 2017
Member

The motivation is to try to have minimal changes in the new error message
Suggestion (if it works):

errors.TypeError('ERR_INVALID_ARG_TYPE', 'msecs',
                 'a non-negative finite number', msecs);

This comment has been minimized.

@starkwang

starkwang Aug 7, 2017
Author Contributor

The error message will become like:

RangeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type a non-negative finite number

IMHO, we should add a new error code (e.g. ERR_OPT_VALUE_OUT_OF_RANGE), which can be reused in other modules. (e.g. https://github.com/nodejs/node/blob/master/lib/buffer.js#L244)

This comment has been minimized.

@refack

refack Aug 7, 2017
Member

Sounds good 👍 (New error code)

test/parallel/test-timers-enroll-invalid-msecs.js Outdated
[],
'foo',
() => { },
Symbol('foo'),

This comment has been minimized.

@tniessen

tniessen Aug 7, 2017
Member

Style nit: Trailing comma.

@tniessen tniessen dismissed their stale review Aug 7, 2017

Didn't mean to approve, sorry.

@refack refack self-assigned this Aug 7, 2017
@starkwang starkwang force-pushed the starkwang:timers-internal-errors branch 3 times, most recently Aug 7, 2017
@refack
refack approved these changes Aug 7, 2017
Copy link
Member

@refack refack left a comment

💯

lib/internal/errors.js Outdated
@@ -229,6 +229,8 @@ E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
E('ERR_OPT_VALUE_OUT_OF_RANGE', (name, expected ,actual) =>
`The value of "${name}" must be ${expected}. Recieved "${actual}"`);

This comment has been minimized.

@tniessen

tniessen Aug 7, 2017
Member

Spelling: Received

test/parallel/test-internal-errors.js Outdated
@@ -257,6 +257,11 @@ assert.strictEqual(
);

assert.strictEqual(
errors.message('ERR_OPT_VALUE_OUT_OF_RANGE', ['A', 'some values', 'B']),
'The value of "A" must be some values. Recieved "B"'

This comment has been minimized.

@tniessen

tniessen Aug 7, 2017
Member

See above.

lib/internal/errors.js Outdated
@@ -229,6 +229,8 @@ E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
E('ERR_OPT_VALUE_OUT_OF_RANGE', (name, expected ,actual) =>

This comment has been minimized.

@refack

refack Aug 7, 2017
Member

lint in L232:

not ok 3 - /usr/home/iojs/build/workspace/node-test-linter/lib/internal/errors.js
  ---
  message: 'There should be no space before '',''.'
  severity: error
  data:
    line: 232
    column: 49
    ruleId: comma-spacing
  messages:
    - message: 'A space is required after '',''.'
      severity: error
      data:
        line: 232
        column: 49
        ruleId: comma-spacing
  ...
@starkwang starkwang force-pushed the starkwang:timers-internal-errors branch 2 times, most recently Aug 8, 2017
@starkwang
Copy link
Contributor Author

@starkwang starkwang commented Aug 8, 2017

Fixed typo and lint

@jasnell jasnell mentioned this pull request Aug 8, 2017
79 of 80 tasks complete
Copy link
Member

@BridgeAR BridgeAR left a comment

A small nit, LGTM otherwise

lib/internal/errors.js Outdated
@@ -229,6 +229,8 @@ E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported');
E('ERR_OPT_VALUE_OUT_OF_RANGE', (name, expected, actual) =>
`The value of "${name}" must be ${expected}. Received "${actual}"`);

This comment has been minimized.

@BridgeAR

BridgeAR Aug 8, 2017
Member

To keep consistency it would be best to use %s and rely on util.format instead of using a function.

@starkwang starkwang force-pushed the starkwang:timers-internal-errors branch Aug 8, 2017
Copy link
Member

@Fishrock123 Fishrock123 left a comment

tniessen added a commit that referenced this pull request Aug 16, 2017
req.socket._hadError should be set before emitting the error event.

PR-URL: #14659
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@tniessen
Copy link
Member

@tniessen tniessen commented Aug 16, 2017

The above commit 620ba41 should not have referenced this PR, sorry for any confusion.
By the way, we still need someone from @nodejs/ctc to sign this off.

doc/api/errors.md Outdated
@@ -1023,6 +1023,11 @@ Used when a Node.js API is called in an unsupported manner.

For example: `Buffer.write(string, encoding, offset[, length])`

<a id="ERR_OPT_VALUE_OUT_OF_RANGE"></a>
### ERR_OPT_VALUE_OUT_OF_RANGE

This comment has been minimized.

@thefourtheye

thefourtheye Aug 16, 2017
Contributor

Nit: OPT_VALUE is not intuitive. ERR_VALUE_OUT_OF_RANGE would be better I guess.

test/parallel/test-timers-enroll-invalid-msecs.js Outdated

[
-1,
Infinity

This comment has been minimized.

@thefourtheye

thefourtheye Aug 16, 2017
Contributor

Can we include zero, for boundary checking and NaN, for special case?

This comment has been minimized.

@starkwang

starkwang Aug 18, 2017
Author Contributor

Zero is valid for argument msecs. I've added NaN for special case.

@starkwang starkwang force-pushed the starkwang:timers-internal-errors branch Aug 18, 2017
@refack refack added this to In Progress in Error Codes Aug 20, 2017
MSLaguana added a commit to nodejs/node-chakracore that referenced this pull request Aug 21, 2017
req.socket._hadError should be set before emitting the error event.

PR-URL: nodejs/node#14659
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
@starkwang starkwang force-pushed the starkwang:timers-internal-errors branch to 7a09080 Aug 24, 2017
Copy link
Member

@BridgeAR BridgeAR left a comment

Still LGTM

@BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Aug 27, 2017

Landed in 4d893e0

@BridgeAR BridgeAR closed this Aug 27, 2017
BridgeAR added a commit that referenced this pull request Aug 27, 2017
PR-URL: #14659
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
ghost pushed a commit to ayojs/ayo that referenced this pull request Aug 30, 2017
PR-URL: nodejs/node#14659
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
ghost pushed a commit to ayojs/ayo that referenced this pull request Aug 30, 2017
PR-URL: nodejs/node#14659
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@refack refack moved this from In Progress to Done in Error Codes Aug 30, 2017
jasnell added a commit that referenced this pull request Oct 17, 2017
* **async_hooks**
  * Older experimental `async_hooks` APIs have been removed
    [[`d731369b1d`](d731369)]
    **(SEMVER-MAJOR)** [#14414](#14414)

* **Errors**
  * Multiple built in modules have been migrated to use static error codes

* **Domains**
  * The long deprecated `.dispose()` method has been removed
    [[`602fd36d95`](602fd36)]
    **(SEMVER-MAJOR)** [#15412](#15412)

* **File system**
  * `fs.ReadStream` and `fs.WriteStream` now make use of `.destroy()`
    [[`e5c290bed9`](e5c290b)]
    **(SEMVER-MAJOR)** [#15407](#15407)
  * `fs` callbacks are now invoked with an undefined `this` context
    [[`2249234fee`](2249234)]
    **(SEMVER-MAJOR)** [#14645](#14645)

* **HTTP**
  * Socket timeout is set when the socket connects
    [[`10be20a0e8`](10be20a)]
    **(SEMVER-MAJOR)** [#8895](#8895)
  * A bug causing the request `error` event to fire twice has been fixed
    [[`620ba41694`](620ba41)]
    **(SEMVER-MAJOR)** [#14659](#14659)
  * The `pipe` method on `OutgoingMessage` has been disabled
    [[`156549d8ff`](156549d)]
    **(SEMVER-MAJOR)** [#14358](#14358)

* **HTTP/2**
  * The `--expose-http2` command-line argument is no longer required
    [[`f55ee6e24a`](f55ee6e)]
    **(SEMVER-MAJOR)** [#15535](#15535)

* **Internationalization**
  * The `Intl.v8BreakIterator` class has been removed
    [[`668ad44922`](668ad44)]
    **(SEMVER-MAJOR)** [#15238](#15238)

* **OS**
  * `os.EOL` is now read-only
    [[`f6caeb9526`](f6caeb9)]
    **(SEMVER-MAJOR)** [#14622](#14622)

* **Process**
  * It is now possible to pass additional flags to `dlopen`
    [[`5f22375922`](5f22375)]
    **(SEMVER-MAJOR)** [#12794](#12794)

* **Timers**
  * Using a timeout duration larger than 32-bits will now emit a warning
    [[`ce3586da31`](ce3586d)]
    **(SEMVER-MAJOR)** [#15627](#15627)

* **TLS**
  * `parseCertString` has been deprecated
    [[`468110b327`](468110b)]
    **(SEMVER-MAJOR)** [#14249](#14249)
  * Type-checking for `key`, `cert`, and `ca` options has been added
    [[`a7dccd040d`](a7dccd0)]
    **(SEMVER-MAJOR)** [#14807](#14807)
jasnell added a commit that referenced this pull request Oct 29, 2017
* **async_hooks**
  * Older experimental `async_hooks` APIs have been removed
    [[`d731369b1d`](d731369)]
    **(SEMVER-MAJOR)** [#14414](#14414)

* **Errors**
  * Multiple built in modules have been migrated to use static error codes

* **Domains**
  * The long deprecated `.dispose()` method has been removed
    [[`602fd36d95`](602fd36)]
    **(SEMVER-MAJOR)** [#15412](#15412)

* **File system**
  * `fs.ReadStream` and `fs.WriteStream` now make use of `.destroy()`
    [[`e5c290bed9`](e5c290b)]
    **(SEMVER-MAJOR)** [#15407](#15407)
  * `fs` callbacks are now invoked with an undefined `this` context
    [[`2249234fee`](2249234)]
    **(SEMVER-MAJOR)** [#14645](#14645)

* **HTTP**
  * Socket timeout is set when the socket connects
    [[`10be20a0e8`](10be20a)]
    **(SEMVER-MAJOR)** [#8895](#8895)
  * A bug causing the request `error` event to fire twice has been fixed
    [[`620ba41694`](620ba41)]
    **(SEMVER-MAJOR)** [#14659](#14659)
  * The `pipe` method on `OutgoingMessage` has been disabled
    [[`156549d8ff`](156549d)]
    **(SEMVER-MAJOR)** [#14358](#14358)

* **HTTP/2**
  * The `--expose-http2` command-line argument is no longer required
    [[`f55ee6e24a`](f55ee6e)]
    **(SEMVER-MAJOR)** [#15535](#15535)

* **Internationalization**
  * The `Intl.v8BreakIterator` class has been removed
    [[`668ad44922`](668ad44)]
    **(SEMVER-MAJOR)** [#15238](#15238)

* **OS**
  * `os.EOL` is now read-only
    [[`f6caeb9526`](f6caeb9)]
    **(SEMVER-MAJOR)** [#14622](#14622)

* **Process**
  * It is now possible to pass additional flags to `dlopen`
    [[`5f22375922`](5f22375)]
    **(SEMVER-MAJOR)** [#12794](#12794)

* **Timers**
  * Using a timeout duration larger than 32-bits will now emit a warning
    [[`ce3586da31`](ce3586d)]
    **(SEMVER-MAJOR)** [#15627](#15627)

* **TLS**
  * `parseCertString` has been deprecated
    [[`468110b327`](468110b)]
    **(SEMVER-MAJOR)** [#14249](#14249)
  * Type-checking for `key`, `cert`, and `ca` options has been added
    [[`a7dccd040d`](a7dccd0)]
    **(SEMVER-MAJOR)** [#14807](#14807)
jasnell added a commit that referenced this pull request Oct 29, 2017
* **async_hooks**
  * Older experimental `async_hooks` APIs have been removed
    [[`d731369b1d`](d731369)]
    **(SEMVER-MAJOR)** [#14414](#14414)

* **Errors**
  * Multiple built in modules have been migrated to use static error codes

* **Domains**
  * The long deprecated `.dispose()` method has been removed
    [[`602fd36d95`](602fd36)]
    **(SEMVER-MAJOR)** [#15412](#15412)

* **File system**
  * `fs.ReadStream` and `fs.WriteStream` now make use of `.destroy()`
    [[`e5c290bed9`](e5c290b)]
    **(SEMVER-MAJOR)** [#15407](#15407)
  * `fs` callbacks are now invoked with an undefined `this` context
    [[`2249234fee`](2249234)]
    **(SEMVER-MAJOR)** [#14645](#14645)

* **HTTP**
  * Socket timeout is set when the socket connects
    [[`10be20a0e8`](10be20a)]
    **(SEMVER-MAJOR)** [#8895](#8895)
  * A bug causing the request `error` event to fire twice has been fixed
    [[`620ba41694`](620ba41)]
    **(SEMVER-MAJOR)** [#14659](#14659)
  * The `pipe` method on `OutgoingMessage` has been disabled
    [[`156549d8ff`](156549d)]
    **(SEMVER-MAJOR)** [#14358](#14358)

* **HTTP/2**
  * The `--expose-http2` command-line argument is no longer required
    [[`f55ee6e24a`](f55ee6e)]
    **(SEMVER-MAJOR)** [#15535](#15535)

* **Internationalization**
  * The `Intl.v8BreakIterator` class has been removed
    [[`668ad44922`](668ad44)]
    **(SEMVER-MAJOR)** [#15238](#15238)

* **OS**
  * `os.EOL` is now read-only
    [[`f6caeb9526`](f6caeb9)]
    **(SEMVER-MAJOR)** [#14622](#14622)

* **Process**
  * It is now possible to pass additional flags to `dlopen`
    [[`5f22375922`](5f22375)]
    **(SEMVER-MAJOR)** [#12794](#12794)

* **Timers**
  * Using a timeout duration larger than 32-bits will now emit a warning
    [[`ce3586da31`](ce3586d)]
    **(SEMVER-MAJOR)** [#15627](#15627)

* **TLS**
  * `parseCertString` has been deprecated
    [[`468110b327`](468110b)]
    **(SEMVER-MAJOR)** [#14249](#14249)
  * Type-checking for `key`, `cert`, and `ca` options has been added
    [[`a7dccd040d`](a7dccd0)]
    **(SEMVER-MAJOR)** [#14807](#14807)
jasnell added a commit that referenced this pull request Oct 29, 2017
* **async_hooks**
  * Older experimental `async_hooks` APIs have been removed
    [[`d731369b1d`](d731369)]
    **(SEMVER-MAJOR)** [#14414](#14414)

* **Errors**
  * Multiple built in modules have been migrated to use static error codes

* **Domains**
  * The long deprecated `.dispose()` method has been removed
    [[`602fd36d95`](602fd36)]
    **(SEMVER-MAJOR)** [#15412](#15412)

* **File system**
  * `fs.ReadStream` and `fs.WriteStream` now make use of `.destroy()`
    [[`e5c290bed9`](e5c290b)]
    **(SEMVER-MAJOR)** [#15407](#15407)
  * `fs` callbacks are now invoked with an undefined `this` context
    [[`2249234fee`](2249234)]
    **(SEMVER-MAJOR)** [#14645](#14645)

* **HTTP**
  * Socket timeout is set when the socket connects
    [[`10be20a0e8`](10be20a)]
    **(SEMVER-MAJOR)** [#8895](#8895)
  * A bug causing the request `error` event to fire twice has been fixed
    [[`620ba41694`](620ba41)]
    **(SEMVER-MAJOR)** [#14659](#14659)
  * The `pipe` method on `OutgoingMessage` has been disabled
    [[`156549d8ff`](156549d)]
    **(SEMVER-MAJOR)** [#14358](#14358)

* **HTTP/2**
  * The `--expose-http2` command-line argument is no longer required
    [[`f55ee6e24a`](f55ee6e)]
    **(SEMVER-MAJOR)** [#15535](#15535)

* **Internationalization**
  * The `Intl.v8BreakIterator` class has been removed
    [[`668ad44922`](668ad44)]
    **(SEMVER-MAJOR)** [#15238](#15238)

* **OS**
  * `os.EOL` is now read-only
    [[`f6caeb9526`](f6caeb9)]
    **(SEMVER-MAJOR)** [#14622](#14622)

* **Process**
  * It is now possible to pass additional flags to `dlopen`
    [[`5f22375922`](5f22375)]
    **(SEMVER-MAJOR)** [#12794](#12794)

* **Timers**
  * Using a timeout duration larger than 32-bits will now emit a warning
    [[`ce3586da31`](ce3586d)]
    **(SEMVER-MAJOR)** [#15627](#15627)

* **TLS**
  * `parseCertString` has been deprecated
    [[`468110b327`](468110b)]
    **(SEMVER-MAJOR)** [#14249](#14249)
  * Type-checking for `key`, `cert`, and `ca` options has been added
    [[`a7dccd040d`](a7dccd0)]
    **(SEMVER-MAJOR)** [#14807](#14807)
@refack refack removed their assignment Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Error Codes
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.