Uh oh!
There was an error while loading. Please reload this page.
uv: binding improvements - #14933
Conversation
The error message when passing in `err >= 0` to `util._errnoException()` was less than useful.
| else | ||
| errCode = uv.UV_EPIPE; | ||
| const code = uv[`UV_${err.code}`]; | ||
| errCode = err.code && code ? code : uv.UV_EPIPE; |
There was a problem hiding this comment.
teeny tiny suggestion: err.code && code in parentheses might be more readable
There was a problem hiding this comment.
Suggestions:
- This closes over
err, why not hoist it out of the callback, so onlyerrCodegets closed. - if
!err.codethen`UV_${err.code}` == somethinglike('UV_undefined')souv[`UV_${err.code}`] == false - IIFE can be nice:
consterrCode=(()=>{if(!err)return0;returnuv[`UV_${err.code}`]||uv.UV_EPIPE;})();addaleax
commented
Aug 19, 2017
I don’t think this needs to be |
| else | ||
| errCode = uv.UV_EPIPE; | ||
| const code = uv[`UV_${err.code}`]; | ||
| errCode = err.code && code ? code : uv.UV_EPIPE; |
There was a problem hiding this comment.
Suggestions:
- This closes over
err, why not hoist it out of the callback, so onlyerrCodegets closed. - if
!err.codethen`UV_${err.code}` == somethinglike('UV_undefined')souv[`UV_${err.code}`] == false - IIFE can be nice:
consterrCode=(()=>{if(!err)return0;returnuv[`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); |
There was a problem hiding this comment.
-0 on this.
I like one expression per line...
| }); | ||
| [0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => { | ||
| assert.throws(() => util._errnoException(key), |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
I'm not sure the assert.doesNotThrow is necessary...
There was a problem hiding this comment.
Not strictly necessary but not a problem either
There was a problem hiding this comment.
I think it mangles the actual error a little bit:
node/test/parallel/test-assert.js
Lines 485 to 497 in 467385a
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Personally I'd go:
constkeys=Object.keys(uv).filter(k=>k!=='errname');and drop L10-11
There was a problem hiding this comment.
Not particularly a fan of using filter
| if (key === 'errname') | ||
| return; // skip this | ||
| const val = uv[key]; | ||
| assert.throws(() => uv[key] = 1, |
There was a problem hiding this comment.
AFAICT assignment is not a valid lambda expression, you need to () => { uv[key] = 1; }
There was a problem hiding this comment.
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
Not all comments are blocking, but PTAL. |
jasnell
commented
Aug 19, 2017
It has to be semver-major because of the error message change. |
| var e = new Error(message); | ||
| e.code = name; | ||
| e.errno = name; | ||
| const e = new Error(message); |
There was a problem hiding this comment.
IMHO a new type something like errors.UVError or errors.PlatformError would be nice, but then we'd need to expose it somehow.
There was a problem hiding this comment.
That's not something I want to do in this pr
jasnell
commented
Aug 19, 2017
| var name = errname(err); | ||
| if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { | ||
| throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', | ||
| 'negative number'); |
There was a problem hiding this comment.
Does it make sense to add the actual argument?
There was a problem hiding this comment.
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
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/ |
* 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
Landed in 58831b2 |
* 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>* 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>
Few improvements to
process.binding('uv')Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
uv