Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
repl: fixing undefined in invalid REPL keyword error
When an invalid REPL keyword is used, we actually print `undefined` as
well in the console.

    > process.version
    'v2.3.4'
    > .invalid_repl_command
    Invalid REPL keyword
    undefined
    >

This patch prevents printing `undefined` in this case.

    > process.version
    'v2.3.5-pre'
    > .invalid_repl_command
    Invalid REPL keyword
    >
  • Loading branch information
thefourtheye committed Jul 22, 2015
commit cdc63cbe7d64c7357ba7e9ae5a980b03bcaad2a6
7 changes: 6 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ function REPLServer(prompt,
self.bufferedCommand = '';

// If we got any output - print it (if no error)
if (!e && (!self.ignoreUndefined || ret !== undefined)) {
if (!e &&
// When an invalid REPL command is used, error message is printed
// immediately. We don't have to print anything else. So, only when
// the second argument to this function is there, print it.
arguments.length === 2 &&
(!self.ignoreUndefined || ret !== undefined)) {
self.context._ = ret;
self.outputStream.write(self.writer(ret) + '\n');
}
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ function error_test() {
{ client: client_unix, send: 'url.format("http://google.com")',
expect: 'http://google.com/' },
{ client: client_unix, send: 'var path = 42; path',
expect: '42' }
expect: '42' },
// this makes sure that we don't print `undefined` when we actually print
// the error message
{ client: client_unix, send: '.invalid_repl_command',
expect: 'Invalid REPL keyword\n' + prompt_unix },
]);
}

Expand Down