Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"hello world" bug #43271

Closed
NekoNyanners opened this issue Jun 1, 2022 · 1 comment
Closed

"hello world" bug #43271

NekoNyanners opened this issue Jun 1, 2022 · 1 comment

Comments

@NekoNyanners
Copy link

NekoNyanners commented Jun 1, 2022

Version

v18.2.0

Platform

Linux Neon 5.13.0-44-generic #49~20.04.1-Ubuntu SMP Wed May 18 18:44:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

  • Create a new NodeJS script hello.js
  • Write console.log("hi");
  • Execute with node hello.js > /dev/full

What is the expected behavior?

Non-Zero Exit code and maybe some STDERR output like python3 does, because there is no normal STDOUT output.
e.g. Python3 correctly yields:

Exception ignored in: <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
OSError: [Errno 28] No space left on device

What do you see instead?

No text with a zero exit code as if everything worked perfectly.

strace however shows there has indeed been a problem:

$ strace -etrace=write node hello.js > /dev/full

write(5, "*", 1)                        = 1
write(1, "hi\n", 3)                     = -1 ENOSPC (No space left on device)
write(12, "\1\0\0\0\0\0\0\0", 8)        = 8
+++ exited with 0 +++

Additional information

I recently read about the "hello world bug": https://blog.sunfishcode.online/bugs-in-hello-world/
And I noticed NodeJS is on the list as well: https://github.com/sunfishcode/hello-world-vs-io-errors

I have no idea if this has been presented already and I know this isn't really a major problem.
But I was curious as to why it's fixed in other languages (e.g. present in py2 but fixed in py3) but not in NodeJS.

@bnoordhuis
Copy link
Member

console.log() is not allowed to throw errors, at least not runtime errors: https://console.spec.whatwg.org/#printer

If you use process.stdout.write(), you receive an error. Of course it's then up to you to handle it:

$ node -e 'process.stdout.write("boom", console.error)' > /dev/full

Hope that answers your question.


Aside about https://github.com/sunfishcode/hello-world-vs-io-errors:

they silently swallow I/O errors, which doesn't satisfy common expectations of command-line programs

That's opinion asserted as fact. I hate it when people do that.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants