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

debugger: refactor internal/inspector/_inspect to use more primordials #38406

Merged
merged 1 commit into from
May 3, 2021

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Apr 25, 2021

This is a refactoring of the module to use async/await where it makes more sense, and some other changes to enable ESLint on the file.

The no-restricted-syntax rule is still disabled as the inspector throws custom errors (which we might want to include in internal/errors at some point), and the linter doesn't know promise versions of setTimeout/setInterval.

@github-actions github-actions bot added inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run. labels Apr 25, 2021
lib/internal/inspector/_inspect.js Outdated Show resolved Hide resolved
lib/internal/inspector/_inspect.js Show resolved Hide resolved
child.stderr.on('data', (chunk) => childPrint(chunk, 'stderr'));

let output = '';
return new Promise((resolve) => {
Copy link
Member

Choose a reason for hiding this comment

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

Should this go ahead and use return await Promise so that any possible error stack would include the runScript frame?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow, isn't await <promise> and return <promise> similar when it's the last expression on an async function?

Copy link
Member

Choose a reason for hiding this comment

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

Yes and no. With return <promise> if <promise> rejects, the error stack trace will not include the wrapping async function (in this case runScript). However, when using return await <promise> the error stack will contain runScript.

Copy link
Contributor Author

@aduh95 aduh95 Apr 27, 2021

Choose a reason for hiding this comment

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

Am I doing this wrong? It seems the stack trace does contain the wrapping function in the dummy test cases I've came up with..
V8 DevTools showing stack traces

Also with node:

$ node -e '(async function runScripts(){return new Promise((_,r)=>{r(new Error)})})()'
[eval]:1
(async function runScripts(){return new Promise((_,r)=>{r(new Error)})})()
                                                          ^

Error
    at [eval]:1:59
    at new Promise (<anonymous>)
    at runScripts ([eval]:1:37)
    at [eval]:1:73
    at Script.runInThisContext (node:vm:131:12)
    at Object.runInThisContext (node:vm:308:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3
$ node -e '(async function runScripts(){return new Promise(()=>{throw new Error})})()' 
[eval]:1
(async function runScripts(){return new Promise(()=>{throw new Error})})()
                                                           ^

Error
    at [eval]:1:60
    at new Promise (<anonymous>)
    at runScripts ([eval]:1:37)
    at [eval]:1:73
    at Script.runInThisContext (node:vm:131:12)
    at Object.runInThisContext (node:vm:308:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60)
    at node:internal/main/eval_string:27:3

Copy link
Member

@jasnell jasnell Apr 27, 2021

Choose a reason for hiding this comment

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

Yeah looking at it again, in this particular case returning the Promise is ok Actually no, because of the await. Here's the case that I was talking about:

const { setTimeout } = require('timers/promises');

async function foo() {
  await setTimeout(100);
  return Promise.reject(new Error('boom'));
}

async function bar() {
  return foo();
}

// vs.

async function bar2() {
  return await foo();
}

Running bar() produces an error:

> Uncaught Error: boom
    at foo (REPL33:4:23)

While running bar2() produces an error:

> Uncaught Error: boom
    at foo (REPL33:4:23)
    at async bar2 (REPL41:2:8)

The key is the use of the await in foo... it separates everything that comes after it into a separate stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a V8 bug, interesting. Unless you feel strongly about this, I'm tempted to leave it as is until a linter rule comes to enforce it.

@Trott
Copy link
Member

Trott commented Apr 29, 2021

Needs a rebase. If tests are passing, then 👍 from me.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 3, 2021
@aduh95
Copy link
Contributor Author

aduh95 commented May 3, 2021

Landed in f331a18

@aduh95 aduh95 merged commit f331a18 into nodejs:master May 3, 2021
@aduh95 aduh95 deleted the _inspect-lint branch May 3, 2021 11:56
targos pushed a commit that referenced this pull request May 3, 2021
PR-URL: #38406
Reviewed-By: Rich Trott <rtrott@gmail.com>
@targos targos mentioned this pull request May 3, 2021
@richardlau
Copy link
Member

Re. backport-blocked-v14.x. This uses timers/promises which currently doesn't currently exist on Node.js 14. Promisified setInterval would need #37153, which is semver-minor.

aduh95 added a commit to aduh95/node that referenced this pull request Jul 19, 2021
aduh95 added a commit to aduh95/node that referenced this pull request Jul 20, 2021
aduh95 added a commit to aduh95/node that referenced this pull request Jul 20, 2021
richardlau pushed a commit that referenced this pull request Jul 22, 2021
PR-URL: #38406
Backport-PR-URL: #39446
Reviewed-By: Rich Trott <rtrott@gmail.com>
richardlau pushed a commit that referenced this pull request Jul 22, 2021
PR-URL: #38406
Backport-PR-URL: #39446
Reviewed-By: Rich Trott <rtrott@gmail.com>
@richardlau richardlau mentioned this pull request Jul 22, 2021
foxxyz pushed a commit to foxxyz/node that referenced this pull request Oct 18, 2021
PR-URL: nodejs#38406
Backport-PR-URL: nodejs#39446
Reviewed-By: Rich Trott <rtrott@gmail.com>
debadree25 added a commit to debadree25/node that referenced this pull request Dec 13, 2022
nodejs-github-bot pushed a commit that referenced this pull request Dec 28, 2022
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
vitpavlenko pushed a commit to vitpavlenko/node that referenced this pull request Dec 28, 2022
Refs: nodejs#38406
PR-URL: nodejs#45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
targos pushed a commit that referenced this pull request Jan 1, 2023
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Jan 4, 2023
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Jan 5, 2023
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
juanarbol pushed a commit that referenced this pull request Jan 26, 2023
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
juanarbol pushed a commit that referenced this pull request Jan 31, 2023
Refs: #38406
PR-URL: #45847
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@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. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants