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

util: avoid inline access to Symbol.iterator #43683

Merged

Conversation

cola119
Copy link
Member

@cola119 cola119 commented Jul 5, 2022

Currently util.inspect has the inline access to Symbol.iterator to check if the value to be inspected is an iterator, but it could throw when the value of [Symbol.iterator] throws(has) an error.
This PR replaced the inline access with in operator to be able to inspect correctly.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Jul 5, 2022
Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM, although I can't reproduce the reported behavior (which is against v17.x) with v18.2.0. This is what I see instead:

> util.inspect({get [Symbol.iterator](){ throw Error("boom") }})
Uncaught Error: boom
    at get [Symbol.iterator] (REPL1:1:46)
    at formatRaw (node:internal/util/inspect:857:12)
    at formatValue (node:internal/util/inspect:817:10)
    at Object.inspect (node:internal/util/inspect:347:10)

(Same with node -p '...')

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 5, 2022
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeAR
Copy link
Member

BridgeAR commented Jul 5, 2022

It does not fix: #41244

I removed that from the description above. I have a fix for that and am going to open a PR later on.

@cola119
Copy link
Member Author

cola119 commented Jul 5, 2022

@bnoordhuis The below reproduces the reported behavior (v18.4.0) for the same reason.

util.inspect({
  a: {
    get [Symbol.iterator]() {
      throw Error('boom');
    },
  },
});
> util.inspect({a:{get [Symbol.iterator](){ throw Error("boom") }}})
Uncaught Error [ERR_INTERNAL_ASSERTION]: Error: boom
    at get [Symbol.iterator] (REPL2:1:49)
    at formatRaw (node:internal/util/inspect:862:12)
    at formatValue (node:internal/util/inspect:822:10)
    at formatProperty (node:internal/util/inspect:1824:11)
    at formatRaw (node:internal/util/inspect:1035:9)
    at formatValue (node:internal/util/inspect:822:10)
    at Object.inspect (node:internal/util/inspect:347:10)
    at REPL2:1:6
    at Script.runInThisContext (node:vm:130:12)
    at REPLServer.defaultEval (node:repl:574:29)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at __node_internal_captureLargerStackTrace (node:internal/errors:477:5)
    at new NodeError (node:internal/errors:388:5)
    at Function.fail (node:internal/assert:20:9)
    at handleMaxCallStackSize (node:internal/util/inspect:1464:10)
    at formatRaw (node:internal/util/inspect:1042:12)
    at formatValue (node:internal/util/inspect:822:10)
    at Object.inspect (node:internal/util/inspect:347:10) {
  code: 'ERR_INTERNAL_ASSERTION'
}

@cola119
Copy link
Member Author

cola119 commented Jul 5, 2022

Maybe I'm misunderstanding the cause, but anyway @BridgeAR, thanks for the confirmation.

@BridgeAR
Copy link
Member

BridgeAR commented Jul 5, 2022

@cola119 it is one possibility to trigger the issue. There are other ways to trigger the internal error as well.

@aduh95 aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 7, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 7, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 9, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 9, 2022
@nodejs-github-bot nodejs-github-bot merged commit 550e814 into nodejs:main Jul 9, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 550e814

targos pushed a commit that referenced this pull request Jul 12, 2022
PR-URL: #43683
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this pull request Jul 20, 2022
PR-URL: #43683
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
targos pushed a commit that referenced this pull request Jul 31, 2022
PR-URL: #43683
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
PR-URL: nodejs/node#43683
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants