Skip to content
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

errors: minor (SystemError) refactoring #20337

Closed
wants to merge 1 commit into from

Conversation

BridgeAR
Copy link
Member

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

@BridgeAR BridgeAR added the fast-track PRs that do not need to wait for 48 hours to land. label Apr 26, 2018
@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Apr 26, 2018
addaleax
addaleax previously approved these changes Apr 26, 2018
@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 26, 2018
@@ -98,7 +98,6 @@ function sysErrorMessage(prefix, ctx) {
// and may have .path and .dest.
class SystemError extends Error {
constructor(key, context = {}) {
context = context || {};
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, This is not really a duplicated default. This is there to catch the possibility of something like new SystemError('foo', null), which is not handled by the default argument.

Copy link
Member

Choose a reason for hiding this comment

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

In that case we could still remove the default argument in the parameter list, right?

Copy link
Member

Choose a reason for hiding this comment

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

The current way SystemErrors are instantiated in the code base warrants that context would at least be a {}, theoretically we don't even need to handle the default argument if we are being careful with new SystemErrors.

@Trott
Copy link
Member

Trott commented Apr 26, 2018

-1 to fast-tracking.

The edge case @jasnell describes likely warrants a test case.

@Trott Trott removed the fast-track PRs that do not need to wait for 48 hours to land. label Apr 26, 2018
@BridgeAR
Copy link
Member Author

I pushed another commit to remove the default values completely. They were not used at the moment. I also removed spread arguments that were unnecessary and was able to remove the default arguments in message. I renamed that function to getMessage to make clear that it is actually a function and a getter.

It is actually better not to have any default values for SystemError because that way we will detect faulty implementations early.

I also inlined a function that was only there to generate the message for SystemErrors and I found some dead code in a test. I kept it there because it seems to mirror some internal functionality.

@BridgeAR BridgeAR changed the title errors: remove duplicated default value errors: minor (SystemError) refactoring Apr 27, 2018
@BridgeAR BridgeAR dismissed addaleax’s stale review April 27, 2018 12:10

Removed due to the changed code. PTAL

@BridgeAR
Copy link
Member Author

@joyeecheung @jasnell @addaleax PTAL

@BridgeAR
Copy link
Member Author

BridgeAR commented Apr 27, 2018

@BridgeAR BridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 27, 2018
@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Apr 27, 2018
@BridgeAR BridgeAR force-pushed the remove-obsolete-line branch from 3cb2e38 to 67612d0 Compare April 29, 2018 15:25
@BridgeAR
Copy link
Member Author

Rebased due to conflicts.

New CI https://ci.nodejs.org/job/node-test-pull-request/14583/

BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 30, 2018
This removes the former default values and the spread arguments
usage. That was unnecessary and now it does only what is necessary.
The `message` function got renamed to `getMessage` to outline that
it is actually a function and a helper function was inlined into
the SystemError constructor as it was only used there.

PR-URL: nodejs#20337
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR
Copy link
Member Author

Landed in 109cfa1

@BridgeAR BridgeAR closed this Apr 30, 2018
MylesBorins pushed a commit that referenced this pull request May 4, 2018
This removes the former default values and the spread arguments
usage. That was unnecessary and now it does only what is necessary.
The `message` function got renamed to `getMessage` to outline that
it is actually a function and a helper function was inlined into
the SystemError constructor as it was only used there.

PR-URL: #20337
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@nelsonlarocca
Copy link

nelsonlarocca commented May 7, 2018 via email

@devsnek devsnek removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 7, 2018
@MylesBorins MylesBorins mentioned this pull request May 8, 2018
@BridgeAR BridgeAR deleted the remove-obsolete-line branch January 20, 2020 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants