-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
repl: fix error message #13733
repl: fix error message #13733
Conversation
Side note: There is an error code |
Good catch. It is indeed not used and it is very similar to the |
I am actually not too sure whether this is correct as it is. Considering that |
I think what @tniessen says makes sense (but tbh I’ve never actually seen this error happen in the wild) |
I changed the error to |
I think this should be semver-major due to the changed error code. @jasnell Are you okay with this? Gonna land it then. |
Wait, this should not be merged as is. The error is actually completely obsolete and it does not matter what is thrown as the catch block is going to catch the error and return a new and different one that has nothing to do with this error. I'm thinking about fixing it like this: try {
// Pre-v3.0, repl history was stored as JSON.
// Try and convert it to line separated history.
const oldReplJSONHistory = fs.readFileSync(oldHistoryPath, 'utf8');
// Only attempt to use the history if there was any.
if (oldReplJSONHistory) repl.history = JSON.parse(oldReplJSONHistory);
} catch (err) {
return ready(
new errors.Error('ERR_PARSE_HISTORY_DATA', oldHistoryPath));
}
if (!Array.isArray(repl.history)) {
return ready(new errors.TypeError('ERR_INVALID_REPL_HISTORY',
typeof repl.history));
}
repl.history = repl.history.slice(0, repl.historySize); This also needs tests as they are missing and lead to the error in the first place. What do you all think? Note to myself: check #2449 |
You are right, I did not even look at that before. Knowing this it makes even less sense why there is |
I fixed the error handling in a way that I expect was originally meant. I am not a big fan of it though and while working on it I thought it might be worth thinking about simple removing the old history file, so I opened an alternative: #13876 |
As suggested in #13876 the way would be to make a end of life deprecation and then remove this part overall. But until then this fix could go into the code base and I think it could even be backported as well and is a semver-patch. So PTAL |
CI: https://ci.nodejs.org/job/node-test-pull-request/8849/ @jasnell @lpinca @cjihrig There have been some major changes since your approvals, could you PTAL and just give me a thumb up if you are okay with landing this as it is? |
This has conflicts. |
Rebased |
lib/internal/repl.js
Outdated
@@ -124,6 +125,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { | |||
} | |||
|
|||
function onread(err, data) { | |||
var threw; |
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.
Nit: why not putting this in the if
branch where the try...catch
is defined?
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.
Done
lib/internal/repl.js
Outdated
// Grab data from the older pre-v3.0 JSON NODE_REPL_HISTORY_FILE format. | ||
_writeToOutput( | ||
repl, | ||
'\nConverting old JSON repl history to line-separated history.\n' + |
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.
Nit: I don't think this is a problem but this message is now displayed after the conversion is actually done.
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.
This was intentional as the message would otherwise be visible even though the conversion did not occur due to e.g. ENOENT
or a parsing error etc.
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.
Yes, I'm fine with this it's just that "converting" suggests that conversion is still happening so it makes sense to display it even if there is a parse error.
I would use "Converted" now.
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.
Addressed
By the way: IMHO this should not be semver-major (if by any means, then because of the change from |
CI: https://ci.nodejs.org/job/node-test-pull-request/8885/ Please fix CI failures. |
Fixed |
New CI: https://ci.nodejs.org/job/node-test-pull-request/8890/ I will land this after giving @nodejs/ctc some time to review and decide semver-ity (even though - technically - two CTC members have already approved). |
As far as I can tell this only affects the REPL, as in, the application built into Node, not the public |
PR-URL: nodejs#13733 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
This doesn’t land cleanly on 8.x; if you can, please follow the guide and raise a backport PR, if you don’t think it’s worth it (or wrong) let me know and we’ll add the |
PR-URL: nodejs#13733 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
@addaleax I opened a backport to 8.x |
Backport-PR-URL: #14392 Backport-Reviewed-By: James M Snell <[email protected]> PR-URL: #13733 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Backport-PR-URL: #14392 Backport-Reviewed-By: James M Snell <[email protected]> PR-URL: #13733 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
Should this be backported to |
I do not think that it is worth backporting. So I changed the label accordingly. |
While looking at the
ERR_INVALID_ARG_TYPE
errors, I stumbled across this one. The property name should be passed to the internal error instead of the type.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl