FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

uv: binding improvements by jasnell · Pull Request #14933 · nodejs/node · GitHub

/ node Public

uv: binding improvements - #14933

Closed
jasnell wants to merge 4 commits into
nodejs:masterfrom
jasnell:uv-binding-improvements
Closed

uv: binding improvements#14933
jasnell wants to merge 4 commits into
nodejs:masterfrom
jasnell:uv-binding-improvements

Conversation

jasnell commented Aug 18, 2017

Copy link
Copy Markdown
Member

Few improvements to process.binding('uv')

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)

uv

jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 18, 2017
jasnell requested review from addaleax and cjihrig August 18, 2017 23:35
nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Aug 18, 2017
Comment thread lib/_stream_wrap.js Outdated
else
errCode = uv.UV_EPIPE;
const code = uv[`UV_${err.code}`];
errCode = err.code && code ? code : uv.UV_EPIPE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

teeny tiny suggestion: err.code && code in parentheses might be more readable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Suggestions:

  • This closes over err, why not hoist it out of the callback, so only errCode gets closed.
  • if !err.code then `UV_${err.code}` == somethinglike('UV_undefined') so uv[`UV_${err.code}`] == false
  • IIFE can be nice:
const errCode = (() => {
  if (!err) return 0;
  return uv[`UV_${err.code}`] || uv.UV_EPIPE;
})();

Copy link
Copy Markdown
Member

I don’t think this needs to be semver-major.

refack previously requested changes Aug 19, 2017
Comment thread lib/_stream_wrap.js Outdated
else
errCode = uv.UV_EPIPE;
const code = uv[`UV_${err.code}`];
errCode = err.code && code ? code : uv.UV_EPIPE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Suggestions:

  • This closes over err, why not hoist it out of the callback, so only errCode gets closed.
  • if !err.code then `UV_${err.code}` == somethinglike('UV_undefined') so uv[`UV_${err.code}`] == false
  • IIFE can be nice:
const errCode = (() => {
  if (!err) return 0;
  return uv[`UV_${err.code}`] || uv.UV_EPIPE;
})();

// cluster modules for stuff like this.
const errno = uv['UV_' + err.errno];
send(errno, null);
send(uv[`UV_${err.errno}`], null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

-0 on this.
I like one expression per line...

Comment thread test/parallel/test-uv-errno.js Outdated
});

[0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => {
assert.throws(() => util._errnoException(key),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You can use the new expectsError syntex:

common.expectsError(
  () => util._errnoException(key),
  {
    code: 'ERR_INVALID_ARG_TYPE',
    type: TypeError,
    message: 'The "err" argument must be of type negative number'
  }
);

if (key === 'errname')
return;

assert.doesNotThrow(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure the assert.doesNotThrow is necessary...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not strictly necessary but not a problem either

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think it mangles the actual error a little bit:

{
let threw = false;
try {
assert.doesNotThrow(makeBlock(thrower, Error));
} catch (e) {
threw = true;
common.expectsError({
code: 'ERR_ASSERTION',
message: /Got unwanted exception\.\n\[object Object\]/
})(e);
}
assert.ok(threw);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm aware of what the function does. These cases do not throw

const util = require('util');
const uv = process.binding('uv');

const keys = Object.keys(uv);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Personally I'd go:

const keys = Object.keys(uv).filter(k => k !== 'errname');

and drop L10-11

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not particularly a fan of using filter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ack.

if (key === 'errname')
return; // skip this
const val = uv[key];
assert.throws(() => uv[key] = 1,

refack Aug 19, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

AFAICT assignment is not a valid lambda expression, you need to () => { uv[key] = 1; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

So what am I thinking us 😕? I remember an old debate that ended up with the invention of Object.assign().
Ohh it return the LHS, not the object.

refack commented Aug 19, 2017

Copy link
Copy Markdown
Contributor

Not all comments are blocking, but PTAL.

jasnell commented Aug 19, 2017

Copy link
Copy Markdown
Member Author

It has to be semver-major because of the error message change.

Comment thread lib/util.js
var e = new Error(message);
e.code = name;
e.errno = name;
const e = new Error(message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

IMHO a new type something like errors.UVError or errors.PlatformError would be nice, but then we'd need to expose it somehow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's not something I want to do in this pr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed.

refack dismissed their stale review August 19, 2017 02:38

Comments have been discussed.

mscdex added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Aug 19, 2017

jasnell commented Aug 19, 2017

Copy link
Copy Markdown
Member Author

Comment thread lib/util.js
var name = errname(err);
if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err',
'negative number');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does it make sense to add the actual argument?

jasnell Aug 20, 2017
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Not particularly useful. The ERR_INVALID_ARG_TYPE actual prints out the type of the actual, not the value itself. So if I passed in _errnoException(1), the error message would be The "err" argument must be of type negative number. Received type number, which is just odd. We could turn this into a RangeError if the err is a number and isn't negative, but that adds a second if-check that is not strictly necessary for what is supposed to be an internal API.

jasnell commented Aug 21, 2017

Copy link
Copy Markdown
Member Author

CI run was a bit too red, although all of the failures were unrelated. Running again just to be safe: https://ci.nodejs.org/job/node-test-pull-request/9778/

jasnell added a commit that referenced this pull request Aug 23, 2017
* ensure that UV_... props are constants
* improve error message ... the error message when passing
  in `err >= 0` to `util._errnoException()` was less than
   useful.
* refine uses of process.binding('uv')

PR-URL: #14933
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

jasnell commented Aug 23, 2017

Copy link
Copy Markdown
Member Author

Landed in 58831b2

jasnell closed this Aug 23, 2017
addaleax pushed a commit to addaleax/ayo that referenced this pull request Aug 25, 2017
* ensure that UV_... props are constants
* improve error message ... the error message when passing
  in `err >= 0` to `util._errnoException()` was less than
   useful.
* refine uses of process.binding('uv')

PR-URL: nodejs/node#14933
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Aug 28, 2017
* ensure that UV_... props are constants
* improve error message ... the error message when passing
  in `err >= 0` to `util._errnoException()` was less than
   useful.
* refine uses of process.binding('uv')

PR-URL: nodejs/node#14933
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. libuv Issues and PRs related to the libuv dependency or the uv binding. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL