| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
|
Not sure what else this effects… but conceptually seems very reasonable to me! 😄 |
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
|
@H4ad some windows runs failed with a related issue: (I think it might be because of the space character ending the command?) 12:12:01 not ok 126 parallel/test-cli-eval
12:12:01 ---
12:12:01 duration_ms: 1887.13100
12:12:01 severity: fail
12:12:01 exitcode: 1
12:12:01 stack: |-
12:12:01 node:assert:1000
12:12:01 throw newErr;
12:12:01 ^
12:12:01
12:12:01 AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Command failed: "c:\workspace\node-test-binary-windows-js-suites\node\Release\node.exe" --print 'Promise.resolve().then(() => 10)'
12:12:01 [eval]:1
12:12:01
12:12:01 'Promise.resolve().then(()
12:12:01
12:12:01 ^^^^^^^^^^^^^^^^^^^^^^^^^^
12:12:01
12:12:01
12:12:01
12:12:01 SyntaxError: Invalid or unexpected token
12:12:01
12:12:01 at makeContextifyScript (node:internal/vm:185:14)
12:12:01
12:12:01 at node:internal/process/execution:109:22
12:12:01
12:12:01 at [eval]-wrapper:6:24
12:12:01
12:12:01 at runScript (node:internal/process/execution:103:62)
12:12:01
12:12:01 at evalScript (node:internal/process/execution:140:3)
12:12:01
12:12:01 at node:internal/main/eval_string:51:3
12:12:01
12:12:01
12:12:01
12:12:01 Node.js v22.0.0-pre
12:12:01
12:12:01
12:12:01 at genericNodeError (node:internal/errors:984:15)
12:12:01 at wrappedFn (node:internal/errors:538:14)
12:12:01 at ChildProcess.exithandler (node:child_process:422:12)
12:12:01 at ChildProcess.emit (node:events:519:28)
12:12:01 at maybeClose (node:internal/child_process:1105:16)
12:12:01 at Socket.<anonymous> (node:internal/child_process:457:11)
12:12:01 at Socket.emit (node:events:519:28)
12:12:01 at Pipe.<anonymous> (node:net:337:12) {
12:12:01 generatedMessage: false,
12:12:01 code: 'ERR_ASSERTION',
12:12:01 actual: Error: Command failed: "c:\workspace\node-test-binary-windows-js-suites\node\Release\node.exe" --print 'Promise.resolve().then(() => 10)'
12:12:01 [eval]:1
12:12:01
12:12:01 'Promise.resolve().then(()
12:12:01
12:12:01 ^^^^^^^^^^^^^^^^^^^^^^^^^^
12:12:01
12:12:01
12:12:01
12:12:01 SyntaxError: Invalid or unexpected token
12:12:01
12:12:01 at makeContextifyScript (node:internal/vm:185:14)
12:12:01
12:12:01 at node:internal/process/execution:109:22
12:12:01
12:12:01 at [eval]-wrapper:6:24
12:12:01
12:12:01 at runScript (node:internal/process/execution:103:62)
12:12:01
12:12:01 at evalScript (node:internal/process/execution:140:3)
12:12:01
12:12:01 at node:internal/main/eval_string:51:3
12:12:01
12:12:01
12:12:01
12:12:01 Node.js v22.0.0-pre
12:12:01
12:12:01
12:12:01 at genericNodeError (node:internal/errors:984:15)
12:12:01 at wrappedFn (node:internal/errors:538:14)
12:12:01 at ChildProcess.exithandler (node:child_process:422:12)
12:12:01 at ChildProcess.emit (node:events:519:28)
12:12:01 at maybeClose (node:internal/child_process:1105:16)
12:12:01 at Socket.<anonymous> (node:internal/child_process:457:11)
12:12:01 at Socket.emit (node:events:519:28)
12:12:01 at Pipe.<anonymous> (node:net:337:12) {
12:12:01 code: 1,
12:12:01 killed: false,
12:12:01 signal: null,
12:12:01 cmd: `"c:\\workspace\\node-test-binary-windows-js-suites\\node\\Release\\node.exe" --print 'Promise.resolve().then(() => 10)'`
12:12:01 },
12:12:01 expected: null,
12:12:01 operator: 'ifError'
12:12:01 }
12:12:01
12:12:01 Node.js v22.0.0-pre |
Sorry, something went wrong.
|
I have no idea but I will investigate tonight, thanks |
Sorry, something went wrong.
|
@H4ad actually this happens to me on a release as well with the single quotes, but works fine with double quotes 🙂
|
Sorry, something went wrong.
There was a problem hiding this comment.
I think we should keep Promise { <result> } notation. Also, we need to take the never-settling promises into account (i.e. node -p 'new Promise(()=>{})')
Hopefully, if --experimental-detect-module becomes the default, we can enable node -p 'await promise' and avoid the need for a new flag or for "magic" behavior.
Sorry, something went wrong.
This is an issue that you will have once we have top level await, so we can address this issue in other PR.
Well, we should keep it or not?
Currently, the implementation didn't differ if it came from --print or not, so my change will affect both --print and --eval. But if we try to follow the suggestion from Geoffrey, we will have the following result for Promise.resolve(10): --print: 10 Being honest, this suggestion could make more sense but looks weird to have different behavior/output for different flags.
This is a good point, once we have top level await, this magic behavior will be unnecessary but still useful to have. In this way, maybe the suggestion by Geoffrey makes more sense. EditActually, my take about --print and --eval didn't make sense, my change only affects --print and should only affect this flag. So, I still prefer to keep the final result WITHOUT the Promise { }. |
Sorry, something went wrong.
There was a problem hiding this comment.
Here's my suggestion: we're still logging the raw input, but we wait for the process to exit to do so. I see two upsides for doing this:
| if (isPromise(result)) { | |
| PromisePrototypeThen(result, (resultValue) => log(resultValue)); | |
| } else { | |
| log(result); | |
| } | |
| process.on('exit', () => { | |
| log(result); | |
| }); |
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
There was a problem hiding this comment.
Please consider copy pasting your console output rather than sharing screenshots, as screenshots might be harder to interpret for e.g. folks using screen readers, and it makes it much harder to copy/paste if someone wants to reproduce what you did.
do we really want to have different behavior with them in this utility?
I think we do.
If we all agree that my suggestion is an improvement, we could start by landing that, and let's start another discussion to try to find consensus – or if you prefer I can open a PR with my suggestion.
Sorry, something went wrong.
There was a problem hiding this comment.
If we all agree that my suggestion is an improvement, we could start by landing that
I liked the idea of putting the print on process.on('exit'), I will keep that, but how we want to print the results is something we need to decide and I think we should decide in this PR to land everything together.
Initially, @mcollina raised the same concern but later dismissed their request change for that, currently, I think you are the only one who thinks we should print the Promise { result } now.
Sorry, something went wrong.
There was a problem hiding this comment.
I don't see the point in waiting for a decision, on the contrary we should make small incremental improvements. I'll open a PR with my suggestion if that's OK.
Sorry, something went wrong.
There was a problem hiding this comment.
If you remove the Request Change for this PR, I'm okay with you creating another PR.
I push the changes with process.on
Sorry, something went wrong.
There was a problem hiding this comment.
I've opened #52137, I suggest we fast-track it, and you can rebase you PR on top of it and we can see better what diff your PR introduces for the various cases I suggested there.
Sorry, something went wrong.
Sorry, something went wrong.
|
Force pushed/rebased just to include the tests added by @aduh95. |
Sorry, something went wrong.
There was a problem hiding this comment.
Can you keep the test cases in the same order so git shows the diff in a more straight forward way?
Sorry, something went wrong.
There was a problem hiding this comment.
Like I said above, I don't think the current PR is improving things if there are cases where nothing at all get printed to the stdout.
I also think the auto-await feature is not desirable: -p is used as a debugging feature, and therefor indicate when the value is a promise / thenable. Adding .then(console.log) is an existing workaround for folks who try to get promise result from a script.
Sorry, something went wrong.
| signal: null, | ||
| stderr: '', | ||
| stdout: 'Promise { <pending> }\n', | ||
| stdout: '', |
There was a problem hiding this comment.
I don't think it's acceptable.
Sorry, something went wrong.
| signal: null, | ||
| stderr: '', | ||
| stdout: 'Promise { <pending> }\n', | ||
| stdout: '', |
There was a problem hiding this comment.
Same here.
Sorry, something went wrong.
| signal: null, | ||
| stderr: '', | ||
| stdout: 'Promise { <rejected> 1 }\n', | ||
| stdout: '', |
There was a problem hiding this comment.
Same here. I would consider that change semver-major if we stick with it.
Sorry, something went wrong.
| signal: null, | ||
| stderr: '', | ||
| stdout: 'Promise { <pending> }\n', | ||
| stdout: '', |
There was a problem hiding this comment.
Same here.
Sorry, something went wrong.
|
|
||
| assert.strictEqual(result.code, 1); | ||
| assert.strictEqual(result.signal, null); | ||
| assert.strictEqual(result.stdout, ''); |
There was a problem hiding this comment.
Same here.
Sorry, something went wrong.
|
|
||
| assert.strictEqual(result.code, 1); | ||
| assert.strictEqual(result.signal, null); | ||
| assert.strictEqual(result.stdout, ''); |
There was a problem hiding this comment.
Same here.
Sorry, something went wrong.
| process.on('exit', async () => { | ||
| log(await result); |
There was a problem hiding this comment.
My concerns would be addressed if we removed the await here.
| process.on('exit', async () => { | |
| log(await result); | |
| process.on('exit', () => { | |
| log(result); |
Sorry, something went wrong.
Co-authored-by: Vinícius Lourenço <contact@viniciusl.com.br> Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #52172 Refs: #52077 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
| Back | FazBrowse Home | New Git URL |
Inspired by https://twitter.com/jarredsumner/status/1767795689575285214
Wait for Promise resolve when printing any code using --print or --eval.
When throwing an exception, the output is:
Since I'm changing the output, this probably should be marked as major, right?