| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
If we were to do this, I'd prefer to make it part of the migration to using internal/errors.js. See #11273.
Changing error messages like this is a semver-major change and has a very real chance of breaking user code. Accordingly, since we'll be moving this code over to using internal/errors.js anyway, we might as well do both at the same time.
Sorry, something went wrong.
|
@jasnell wrote:
I don't think there's any question we should do this. There is no reason for writeInt8() to return RangeError: Index out of range but writeFloatLE() to return RangeError: out of range index in the code below. let buf = Buffer.alloc(9);
try {
buf.writeInt8(1, -1);
} catch (e) {
console.log(e.toString()); // RangeError: Index out of range
}
try {
buf.writeFloatLE(1, -1);
} catch (e) {
console.log(e.toString()); // RangeError: out of range index
}@jasnell continued:
Would you be OK with that being a subsequent PR? I'd prefer we separate out changes to error messages from migrations to internal/error.js rather than bundling those adjacent-but-not-integrally-related things. I can make sure that second PR happens immediately after this one lands if that affects your spider-sense on this one. |
Sorry, something went wrong.
|
As long as the two land closely together, or perhaps even as two commits in the same PR, that's fine. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM if CI is green. Might be good to edit the commit message to make it clear that this is not changing an error message just to change it, but rather taking two error messages that are used in essentially identical situations and making them consistent.
Sorry, something went wrong.
|
I will clear my "changes requested" review once I get a chance to review the other PR. |
Sorry, something went wrong.
Sorry, something went wrong.
|
@jasnell It looks like sometimes this RangeError is thrown in JS-land (in which case we can migrate to the internal error system) and sometimes it is thrown by C++ (in which case we cannot, right? Maybe I'm wrong?). For the sake of consistency, I wonder if it makes sense to not migrate the JS-land errors to the new system until we can do errors thrown in C++ as well. This way, you don't get very dissimilar RangeError objects depending on whether you are trying to read a float or an int. What do you think? |
Sorry, something went wrong.
|
We're always going to have at least some inconsistency given that errors thrown from V8 will not have this information and neither will userland code. I will work on providing an equivalent mechanism for the errors thrown from C/C++ but I think it makes sense (and is best) to incrementally move forward. If we try to hold off and do them all at once, we're going to end up with too much of a moving target (I've already tried it). I think userland will be willing to forgive some short term inconsistency if it means we're making progress towards something better. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nit: Should this commented-out code be removed?
Sorry, something went wrong.
There was a problem hiding this comment.
ok, fixing it
Sorry, something went wrong.
Sorry, something went wrong.
|
There was a force push right after last CI, so it didn't go through. New CI: https://ci.nodejs.org/job/node-test-pull-request/6519/ |
Sorry, something went wrong.
|
Heh, seems like there is a merge conflict: https://ci.nodejs.org/job/node-test-commit/8037/console @larissayvette can you git rebase master? |
Sorry, something went wrong.
|
Seems to be working now: https://ci.nodejs.org/job/node-test-pull-request/6521/ |
Sorry, something went wrong.
|
Tests are passing (hooray!) but linter is failing because a number of lines in test-buffer-fill.js are longer than 80 characters. Easiest solution is probably to change things like this: assert.throws(() =>
Buffer.allocUnsafe(8).fill('a', -1),
/^RangeError(?:\[ERR_INDEX_OUT_OF_RANGE\])?: Index out of range$/);...to something more like this: assert.throws(
() => Buffer.allocUnsafe(8).fill('a', -1),
/^RangeError(?:\[ERR_INDEX_OUT_OF_RANGE\])?: Index out of range$/
); |
Sorry, something went wrong.
|
Is there a problem using common.expectsError()? |
Sorry, something went wrong.
|
@jasnell when common.expectsError() is used it produces this error |
Sorry, something went wrong.
|
@Trott I think the lint is correct now |
Sorry, something went wrong.
|
On closer inspection, @jasnell is right to suggest that the regular expression is unnecessary in most of the places it's used here. It only needs to be used in places where the throw might be C++ or JS. That's probably only going to happen in test-buffer-write-noassert and/or test-buffer-read. |
Sorry, something went wrong.
There was a problem hiding this comment.
This regexp can be replaced with common.expectsError(undefined, RangeError, 'Index out of range')
Sorry, something went wrong.
There was a problem hiding this comment.
This line can be replaced with:
const oor = common.expectsError('ERR_INDEX_OUT_OF_RANGE');
Will need to change the require('../common'); to const common = require('../common'); too.
Sorry, something went wrong.
There was a problem hiding this comment.
This one (and likely the others in this file) can be replaced with common.expectsError('ERR_INDEX_OUT_OF_RANGE'));. (Will need to add const common = require... at top of file.)
Sorry, something went wrong.
There was a problem hiding this comment.
From line 187 to 196 , test passes only when it is regular expression. and for the subsequent error message it is common.expectsError(undefined, RangeError, 'Index out of range')); that works and not common.expectsError('ERR_INDEX_OUT_OF_RANGE'));
Sorry, something went wrong.
There was a problem hiding this comment.
I think this is the only regexp that should stay because we don't know ahead of time whether the error is coming from JS (if writing an int, for example) or C++ (if writing a float, for example).
Sorry, something went wrong.
There was a problem hiding this comment.
+1... we should probably look at fixing up common.expectsError() to account for this, however. Will have to think on that for a bit
Sorry, something went wrong.
There was a problem hiding this comment.
@jasnell If we really wanted to use common.expectsError() and not a RegExp, we could do something like the following (untested) code:
let expectedError;
if (['writeFloatBE', 'writeFloatLE'].includes(funx)) {
expectedError = common.expectsError(undefined, RangeError, 'Index out of range');
} else {
expectedError = common.expectsError('ERR_INDEX_OUT_OF_RANGE', RangeError, 'Index out of range');
}
assert.throws(() => { Buffer.alloc(9)[funx](...invalidArgs) }, expectedError);Definitely more complicated, though, so I'm fine with the RegExp approach. Either way.
Sorry, something went wrong.
There was a problem hiding this comment.
bleh... let's keep it with the regex for now
Sorry, something went wrong.
|
Keep in mind also that eventually, even the C/C++ errors thrown by Node.js will include these codes and the augmented name. We'll still need to be careful about errors thrown by V8 or Chakra |
Sorry, something went wrong.
There was a problem hiding this comment.
I would suggest rewording just a bit here...
The `'ERR_INDEX_OUT_OF_RANGE'` error code is used when a given index is out of the accepted range.
Sorry, something went wrong.
There was a problem hiding this comment.
I will make the change
Sorry, something went wrong.
There was a problem hiding this comment.
For the cases where the regex must still be provided, it would be easiest to change later on if the regex was defined once and assigned then used multiple times... e.g.
const errRegex = /^RangeError .../;
assert.throws(() => { /* ... */ }, errRegex);
assert.throws(() => { /* ... */ }, errRegex);
Sorry, something went wrong.
There was a problem hiding this comment.
Can this be require('internal/errors'); along with a // Flags: --expose-internals comment at the top of the file instead?
Sorry, something went wrong.
There was a problem hiding this comment.
I don't think we need errRegex in this file. I think all instances of it can be replaced with common.expectsError().
Sorry, something went wrong.
There was a problem hiding this comment.
I think the comment needs to be the first line of the file. The idea of using it is to be able to change ../../lib/internal/errors on this line to internal/errors. This way, the test runs based on version of node that is compiled and not the contents of lib in the source tree at the time the test is run.
Sorry, something went wrong.
There was a problem hiding this comment.
(Also, it means that in order to run the test from the command line, you need to either use tools/test.py or else pass the --expose-internals flag to node. But lots of tests are like that already, so that should be fine.)
Sorry, something went wrong.
There was a problem hiding this comment.
Indeed. The // Flags: --expose-internals should be the first line of the test file,
The import must also be require('internal/errors'), without the ../../lib/ part.
Sorry, something went wrong.
|
@jasnell Two things: Can you give this another look since it has changed a bit? Also, are we not landing these new internal error things on master yet? What needs to happen before we can start doing that? |
Sorry, something went wrong.
|
Oh, it looks like this needs to be updated for the new common.expectsError() signature. Instead of common.expectsError(code, type, msg), it's now common.expectsError({code, type, message: msg}). |
Sorry, something went wrong.
Sorry, something went wrong.
|
Rebased and force pushed. |
Sorry, something went wrong.
|
Landed in 234353a. |
Sorry, something went wrong.
PR-URL: #11296 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
lib, src
Changing where RangeError was out of range index to Index out of range