FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

src: don't print garbage errors by cjihrig · Pull Request #4112 · nodejs/node · GitHub

/ node Public

src: don't print garbage errors - #4112

Closed
cjihrig wants to merge 1 commit into
nodejs:masterfrom
cjihrig:4079
Closed

src: don't print garbage errors#4112
cjihrig wants to merge 1 commit into
nodejs:masterfrom
cjihrig:4079

Conversation

cjihrig commented Dec 2, 2015

Copy link
Copy Markdown
Contributor

If JS throws an object whose toString() method throws, then Node attempts to print an empty message, but actually prints garbage. This commit checks for this case, and prints a newline instead.

Closes #4079

mscdex added the c++ Issues and PRs that require attention from people who are familiar with C++. label Dec 2, 2015

Copy link
Copy Markdown
Contributor

LGTM.

Comment thread src/node.cc Outdated

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You could simplify this to PrintErrorString("%s\n", *message ? *message : "");

I would print a message like "<toString() threw exception>" instead of a blank line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would print a message like "<toString() threw exception>" instead of a blank line.

I thought about that, but the current check is insufficient, since empty string is a valid toString() response. Would you be OK with me using a TryCatch to actually detect if an error was thrown?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I mean when *message == nullptr, that means .toString() failed somehow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That doesn't seem to be the case though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@bnoordhuis is *message == nullptr for you? If so, it might be platform specific based on #4079 (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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, I missed that it's using node::Utf8Value (which indeed never returns a nullptr because it returns a pointer to its embedded char array.)

If you use String::Utf8Value, you should see *message == nullptr after a .toString() exception.

jasnell commented Dec 3, 2015

Copy link
Copy Markdown
Member

LGTM once @bnoordhuis is happy with it

Copy link
Copy Markdown
Member

LGTM

JungMinu commented Dec 4, 2015

Copy link
Copy Markdown
Member

JungMinu commented Dec 4, 2015

Copy link
Copy Markdown
Member

LGTM

JungMinu commented Dec 4, 2015

Copy link
Copy Markdown
Member

Would you mind if I land this PR? 😄

cjihrig commented Dec 4, 2015

Copy link
Copy Markdown
Contributor Author

@JungMinu Don't land it yet, as the test fails on Windows.

I'd also like @bnoordhuis's input. message alone, at least on OS X, doesn't seem to provide enough information to differentiate between a toString() error, and a valid empty string result. Do you think it's worth using a TryCatch to differentiate between the two? I've implemented it, and it seems very straightforward.

JungMinu commented Dec 5, 2015

Copy link
Copy Markdown
Member

@cjihrig Sorry to bug you, It slipped my mind. 😢

JungMinu commented Dec 5, 2015

Copy link
Copy Markdown
Member

IMHO, I think that using a TryCatch to differentiate between the two is fine :)
(I guess that I saw some similar cases in code base before)

If JS throws an object whose toString() method throws, then Node
attempts to print an empty message, but actually prints garbage.
This commit checks for this case, and prints a message instead.

cjihrig commented Dec 5, 2015

Copy link
Copy Markdown
Contributor Author

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

Made the change to String::Utf8Value. @bnoordhuis still LGTY?

cjihrig commented Dec 5, 2015

Copy link
Copy Markdown
Contributor Author

CI failures are unrelated.

Copy link
Copy Markdown
Member

LGTM

cjihrig added a commit that referenced this pull request Dec 5, 2015
If JS throws an object whose toString() method throws, then Node
attempts to print an empty message, but actually prints garbage.
This commit checks for this case, and prints a message instead.

Fixes: #4079
PR-URL: #4112
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>

cjihrig commented Dec 5, 2015

Copy link
Copy Markdown
Contributor Author

Thanks, landed in 1ec09b0.

cjihrig closed this Dec 5, 2015
cjihrig deleted the 4079 branch December 5, 2015 16:16
cjihrig added a commit that referenced this pull request Dec 8, 2015
If JS throws an object whose toString() method throws, then Node
attempts to print an empty message, but actually prints garbage.
This commit checks for this case, and prints a message instead.

Fixes: #4079
PR-URL: #4112
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
rvagg mentioned this pull request Dec 17, 2015
cjihrig added a commit that referenced this pull request Dec 29, 2015
If JS throws an object whose toString() method throws, then Node
attempts to print an empty message, but actually prints garbage.
This commit checks for this case, and prints a message instead.

Fixes: #4079
PR-URL: #4112
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 19, 2016
If JS throws an object whose toString() method throws, then Node
attempts to print an empty message, but actually prints garbage.
This commit checks for this case, and prints a message instead.

Fixes: #4079
PR-URL: #4112
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
MylesBorins mentioned this pull request Jan 19, 2016
EhabY added a commit to coder/vscode-coder that referenced this pull request Apr 30, 2026
Forwarding CODER_SESSION_TOKEN via the child env exposed it to any
sibling process via /proc/<pid>/environ on Linux and similar interfaces
elsewhere. Drop all env injection from cliExec and instead refresh the
file or keyring once via cliManager.configure inside resolveCliEnv,
mirroring the connection-time write in remote.ts. The CLI reads the
fresh token from the file (or keyring on supported systems) via the
existing --global-config / --url flags. mTLS still works since the
refresh accepts an empty token.

Also drop the keyringOnly option from storeToken (no longer needed now
that we always refresh) and update the matching tests.

Add writeStdoutJs / writeStderrJs helpers in test/utils/platform.ts that
generate fs.writeSync snippets, and use them in the cliExec and platform
tests. process.stdout/stderr.write is async on POSIX pipes and can be
lost on exit (nodejs/node#4112), which was making the version fallback
test flaky.
EhabY added a commit to coder/vscode-coder that referenced this pull request Apr 30, 2026
Forwarding CODER_SESSION_TOKEN via the child env exposed it to any
sibling process via /proc/<pid>/environ on Linux and similar interfaces
elsewhere. Drop all env injection from cliExec and instead refresh the
file or keyring once via cliManager.configure inside resolveCliEnv,
mirroring the connection-time write in remote.ts. The CLI reads the
fresh token from the file (or keyring on supported systems) via the
existing --global-config / --url flags. mTLS still works since the
refresh accepts an empty token.

Also drop the keyringOnly option from storeToken (no longer needed now
that we always refresh) and update the matching tests.

Add writeStdoutJs / writeStderrJs helpers in test/utils/platform.ts that
generate fs.writeSync snippets, and use them in the cliExec and platform
tests. process.stdout/stderr.write is async on POSIX pipes and can be
lost on exit (nodejs/node#4112), which was making the version fallback
test flaky.
EhabY added a commit to coder/vscode-coder that referenced this pull request Apr 30, 2026
Forwarding CODER_SESSION_TOKEN via the child env exposed it to any
sibling process via /proc/<pid>/environ on Linux and similar interfaces
elsewhere. Drop all env injection from cliExec and instead refresh the
file or keyring once via cliManager.configure inside resolveCliEnv,
mirroring the connection-time write in remote.ts. The CLI reads the
fresh token from the file (or keyring on supported systems) via the
existing --global-config / --url flags. mTLS still works since the
refresh accepts an empty token.

Also drop the keyringOnly option from storeToken (no longer needed now
that we always refresh) and update the matching tests.

Add writeStdoutJs / writeStderrJs helpers in test/utils/platform.ts that
generate fs.writeSync snippets, and use them in the cliExec and platform
tests. process.stdout/stderr.write is async on POSIX pipes and can be
lost on exit (nodejs/node#4112), which was making the version fallback
test flaky.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL