Skip to content

repl: make last error available as _error - #18919

Closed
addaleax wants to merge 3 commits into
nodejs:masterfrom
addaleax:repl-last-error
Closed

repl: make last error available as _error#18919
addaleax wants to merge 3 commits into
nodejs:masterfrom
addaleax:repl-last-error

Conversation

@addaleax

Copy link
Copy Markdown
Member

This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to _,
which contains the last successful completion value.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

repl

@nodejs-github-botnodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Feb 21, 2018
@addaleax

Copy link
Copy Markdown
MemberAuthor

Comment threaddoc/api/repl.md Outdated

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.

Is there any way we could add a Changes section for this?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@Fishrock123

Copy link
Copy Markdown
Contributor

Would it be a good idea to make it something... less likely to conflict? __err or a symbol?

@addaleax

Copy link
Copy Markdown
MemberAuthor

@Fishrock123 How would _err occur naturally in the REPL? I’m open to bikeshedding for the name, but a Symbol would defeat the purpose of making this value easily accessible.

@vdeturckheimvdeturckheim left a comment

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.

love it

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 22, 2018
@jasnell

Copy link
Copy Markdown
Member

Love the idea, needs a better name. Two underscores is better than one and would prefer something like __lastError (that is, slightly more descriptive and not abbreviated)

@addaleax

addaleax commented Feb 22, 2018

Copy link
Copy Markdown
MemberAuthor

@jasnell I think the main goal for the name is that it’s supposed to be typable really, really easily and quickly.

I love verbose names in real code, because we’re writing it for the 100 readers coming after us, but the REPL has the exact opposite goal of that: It’s code that’s only written once, ever, and never read by anybody else more than a minute after it was written. It’s not about choosing good or descriptive variable names in any way, it’s about being easy to write, so I would really prefer to keep it short and succinct.

(Literally all REPLs that I know of use _ or ans for the last value for those very reasons.)

The only thing I’m worried about here is discoverability, because right now you’d have to hear about it somewhere or read the docs. I’ve gone with _err because that’s one of the things I’d type to see whether this feature exists; __lastError is not on that list.

I’m also not worried about collisions; there is an explicit warning text being emitted here if that happens, like it is for _.

@addaleaxaddaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 22, 2018

@tniessentniessen left a comment

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.

LGTM with either name.

@jasnell

Copy link
Copy Markdown
Member

@addaleax ... then how about meeting in the middle with _error?

@addaleax

Copy link
Copy Markdown
MemberAuthor

@jasnell I’m fine with that, but honestly, I’m just going to write _err<TAB> every time. 😄

I’ve switched it for now but it might be helpful to know what your concerns actually are.

@jasnell

Copy link
Copy Markdown
Member

The concern is that I'm not particularly fond of abbreviated things.

@TimothyGu

Copy link
Copy Markdown
Member

How about $err? The $ prefix would be consistent with other command line APIs.

This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.
@addaleaxaddaleax changed the title repl: make last error available as _errrepl: make last error available as _errorFeb 26, 2018
@addaleax

Copy link
Copy Markdown
MemberAuthor

@TimothyGu I think @jasnell would want that to be $error ;) I would kind of like to be consistent with _ too, though…

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 2, 2018
@BridgeAR

Copy link
Copy Markdown
Member

@addaleax

Copy link
Copy Markdown
MemberAuthor

It seems like the CI run here was started for a different PR.

CI: https://ci.nodejs.org/job/node-test-commit/16599/

Leko
Leko approved these changes Mar 3, 2018
@addaleax

Copy link
Copy Markdown
MemberAuthor

Landed in a8b5192

@addaleaxaddaleax closed this Mar 4, 2018
@addaleaxaddaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 4, 2018
addaleax added a commit that referenced this pull request Mar 4, 2018
This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.
PR-URL: #18919
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
addaleax added a commit to addaleax/node that referenced this pull request Mar 5, 2018
This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.
PR-URL: nodejs#18919
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
@MylesBorinsMylesBorins mentioned this pull request Mar 6, 2018
@MylesBorins

Copy link
Copy Markdown
Contributor

Should this be backported to v8.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@addaleaxaddaleax added the semver-minor PRs that contain new features and should be released in the next minor version. label May 2, 2018
@addaleax
addaleax deleted the repl-last-error branch May 2, 2018 16:32
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This is pretty useful when trying to inspect the last
error caught by a REPL, and is made to be analogous to `_`,
which contains the last successful completion value.
PR-URL: nodejs#18919
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replIssues and PRs related to the REPL subsystem.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

15 participants

@addaleax@Fishrock123@jasnell@TimothyGu@BridgeAR@MylesBorins@evanlucas@Leko@princejwesley@targos@cjihrig@tniessen@devsnek@vdeturckheim@nodejs-github-bot