-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
uv: binding improvements #14933
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
uv: binding improvements #14933
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
The error message when passing in `err >= 0` to `util._errnoException()` was less than useful.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1030,13 +1030,16 @@ function error(...args) { | |
| } | ||
|
|
||
| function _errnoException(err, syscall, original) { | ||
| var name = errname(err); | ||
| if (typeof err !== 'number' || err >= 0 || !Number.isSafeInteger(err)) { | ||
| throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'err', | ||
| 'negative number'); | ||
| } | ||
| const name = errname(err); | ||
| var message = `${syscall} ${name}`; | ||
| if (original) | ||
| message += ` ${original}`; | ||
| var e = new Error(message); | ||
| e.code = name; | ||
| e.errno = name; | ||
| const e = new Error(message); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO a new type something like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not something I want to do in this pr
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
| e.code = e.errno = name; | ||
| e.syscall = syscall; | ||
| return e; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||
| 'use strict'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const common = require('../common'); | ||||||||||||||||||||||||||||
| const assert = require('assert'); | ||||||||||||||||||||||||||||
| const util = require('util'); | ||||||||||||||||||||||||||||
| const uv = process.binding('uv'); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const keys = Object.keys(uv); | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I'd go: const keys = Object.keys(uv).filter(k => k !== 'errname');and drop L10-11
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularly a fan of using filter
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| keys.forEach((key) => { | ||||||||||||||||||||||||||||
| if (key === 'errname') | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| assert.doesNotThrow(() => { | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly necessary but not a problem either
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it mangles the actual error a little bit: node/test/parallel/test-assert.js Lines 485 to 497 in 467385a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of what the function does. These cases do not throw |
||||||||||||||||||||||||||||
| const err = util._errnoException(uv[key], 'test'); | ||||||||||||||||||||||||||||
| const name = uv.errname(uv[key]); | ||||||||||||||||||||||||||||
| assert.strictEqual(err.code, err.errno); | ||||||||||||||||||||||||||||
| assert.strictEqual(err.code, name); | ||||||||||||||||||||||||||||
| assert.strictEqual(err.message, `test ${name}`); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| [0, 1, 'test', {}, [], Infinity, -Infinity, NaN].forEach((key) => { | ||||||||||||||||||||||||||||
| assert.throws(() => util._errnoException(key), | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the new common.expectsError(
() => util._errnoException(key),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "err" argument must be of type negative number'
}
); |
||||||||||||||||||||||||||||
| common.expectsError({ | ||||||||||||||||||||||||||||
| code: 'ERR_INVALID_ARG_TYPE', | ||||||||||||||||||||||||||||
| type: TypeError, | ||||||||||||||||||||||||||||
| message: 'The "err" argument must be of type negative number' | ||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add the
actualargument?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not particularly useful. The
ERR_INVALID_ARG_TYPEactual prints out the type of the actual, not the value itself. So if I passed in_errnoException(1), the error message would beThe "err" argument must be of type negative number. Received type number, which is just odd. We could turn this into aRangeErrorif theerris 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.