Skip to content

Commit

Permalink
repl: fixing undefined in invalid REPL keyword error
Browse files Browse the repository at this point in the history
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
    >

PR-URL: #2163
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
thefourtheye committed Jul 24, 2015
1 parent a3c1b97 commit 77fa385
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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

0 comments on commit 77fa385

Please sign in to comment.