Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Console.log fails in Windows TextEditors #1961

Closed
robinmattern opened this issue Oct 28, 2011 · 10 comments
Closed

Console.log fails in Windows TextEditors #1961

robinmattern opened this issue Oct 28, 2011 · 10 comments
Labels

Comments

@robinmattern
Copy link

I am new to node.js, so this may not be a legitimate issue, but I noticed that you are removing process.writeError (see #1860).

This will break the only way that I could display console messages when I test node,js code using the "run" command inside Windows text editors such as TextPad or Komondo. Console.log() fails in this environment, but console.error() does not in version 0.5.9.

I looked at the source for console.error() in version 0.5.9, and I see it uses writeError(), but in version 0.5.10 it uses process.stderr.write(). When I tested this function directly, along with process.stdout.write(), it too fails when run as a batch command from within the two editors I tested.

Here is a listing of a script, test.js, that I wrote and the output that I get when I run it within the text editors. I also ran it in DOS, which works fine, other than the direct call to writeError(), which may be a local, private function.


Here is a test script, E:\test.js, that reproduces the error

        console.error( "" )
        console.error( "  console.error( aStr )            // works in editor, works in DOS" )
           console.log( "  console.log( aStr )               // fails in editor, works in DOS" )

process.stdout.write( " process.stdout.write( aStr ) // fails in editor, works in DOS\n" )
process.stderr.write( " process.stderr.write( aStr ) // fails in editor, works in DOS\n" )
writeError( " writeError( aStr ) // fails in editor, fails in DOS\n" )


In Editor: node.exe E:\test.js // fails on console.log()

console.error( aStr ) // works in editor, works in DOS

node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'write' of null
at Socket.write (net_uv.js:389:31)
at Object. (E:\test.js:5:19)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array. (module.js:470:10)
at EventEmitter._tickCallback (node.js:195:26)


I've seen this error, too:

node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: write EINVAL
at errnoException (net_uv.js:569:11)
at Socket.write (net_uv.js:392:18)
at Object. (E:\test.js:5:19)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array. (module.js:470:10)
at EventEmitter._tickCallback (node.js:195:26)


In DOS: node E:\test.js // fails on writeError()

console.error( aStr ) // works in editor, works in DOS
console.log( aStr ) // fails in editor, works in DOS
process.stdout.write( aStr ) // fails in editor, works in DOS
process.stderr.write( aStr ) // fails in editor, works in DOS

node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
ReferenceError: writeError is not defined
at Object. (E:\test.js:5:19)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array. (module.js:470:10)
at EventEmitter._tickCallback (node.js:195:26)

@bnoordhuis
Copy link
Member

@igorzi, @piscisaureus: Can you review this bug report?

I think @ry is fixing this by making stdio synchronous / flushing on exit.

@igorzi
Copy link

igorzi commented Oct 28, 2011

I don't think this is related. @robinmattern do you know what "run" command in textpad does exactly? Do it redirect stdout/stderr to a pipe? to a file? etc. I'll try to reproduce this.

@igorzi
Copy link

igorzi commented Oct 28, 2011

I can't reproduce this. I ran "node.exe foo.js" using testpad's run command, and it ran fine (with output captured):

console.error("bar");
console.log("foo");

@robinmattern
Copy link
Author

Igor,

Hmmm.... I am running an older version, v4.7.3, of TextPad (not TestPad),
but I get the same error with a current, more popular version of Komondo
(v6.1). I've also tried it a Windows 2008 (64bit) server; my PC is Windows
7 (32bit). Here's are two screen shots:

[image: image.png]

[image: image.png]
On Fri, Oct 28, 2011 at 4:52 PM, Igor Zinkovsky <
[email protected]>wrote:

I can't reproduce this. I ran "node.exe foo.js" using testpad's run
command, and it ran fine (with output captured):

console.error("bar");
console.log("foo");

Reply to this email directly or view it on GitHub:
#1961 (comment)

@robinmattern
Copy link
Author

I guess the images aren't allowed. You can see them at this location, http://www.jscriptware.us/node/console.log-error/ Also, I mispelled the second editor's name, it is Komodo (http://www.activestate.com/komodo-edit). And no, I don't know what they are doing, other than that they are capturing the DOS output (stdout?) into the editor itself.

@GraemeF
Copy link

GraemeF commented Nov 6, 2011

Same thing happens in WebStorm, FWIW.

@ghost ghost assigned igorzi Nov 7, 2011
@igorzi
Copy link

igorzi commented Nov 9, 2011

@robinmattern/@GraemeF, does this reproduce with v0.6.0?

@ry
Copy link

ry commented Nov 10, 2011

related to #2065 ?

@robinmattern
Copy link
Author

I tested v0.6.0 in TextPad on Windows 7 and 2008 and it works like a charm:

Here is a more elaborate test:

  console.log( "\n1. console.trace:");  console.trace( 1 )
  console.log( "\n2. console.log: hello world" )
  console.info("\n3. console.info: some info" )
  console.warn("\n4. console.warn: a warning" )
  console.log( "\n5. console.log: 1 / 0 = %s", 1 / 0 )
  console.log( "\n6. console.log: 1 / {}, 2 = " + 1 / {}, 2 )
  console.log( "\n7. console.dir:"); console.dir( { boolean: 1, array: [1, "two", 3], number: 23.45, date: new Date, identity: 12345, text: "text", object: { obj: { }, arr: [ ] } } )
  try{ 1 + xx } catch(err) { console.error("\n 8. console.error: Value Error:\n%s", err ) }

and the captured output:

  1. console.trace:
  Trace: 1
      at Object.<anonymous> (E:\WEBs\_0\XEQs\Node\foo.js:2:53)
      at Module._compile (module.js:432:26)
      at Object..js (module.js:450:10)
      at Module.load (module.js:351:31)
      at Function._load (module.js:310:12)
      at Array.0 (module.js:470:10)
      at EventEmitter._tickCallback (node.js:192:40)

  2. console.log: hello world

  4. console.warn: a warning

  3. console.info: some info

  8. console.error: Value Error:
  ReferenceError: xx is not defined

  5. console.log: 1 / 0 = Infinity

  6. console.log: 1 / {}, 2 = NaN 2

  7. console.dir:
  { boolean: 1,
    array: [ 1, 'two', 3 ],
    number: 23.45,
    date: Thu, 10 Nov 2011 17:52:43 GMT,
    identity: 12345,
    text: 'text',
    object: { obj: {}, arr: [] } }

  Tool completed successfully

It also works in ActiveState's Komodo, with some color for console.warn, trace and error.

@piscisaureus
Copy link

@robinmattern Ok, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants