Skip to content

Commit 77fa385

Browse files
committed
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 > PR-URL: #2163 Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent a3c1b97 commit 77fa385

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/repl.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,12 @@ function REPLServer(prompt,
342342
self.bufferedCommand = '';
343343

344344
// If we got any output - print it (if no error)
345-
if (!e && (!self.ignoreUndefined || ret !== undefined)) {
345+
if (!e &&
346+
// When an invalid REPL command is used, error message is printed
347+
// immediately. We don't have to print anything else. So, only when
348+
// the second argument to this function is there, print it.
349+
arguments.length === 2 &&
350+
(!self.ignoreUndefined || ret !== undefined)) {
346351
self.context._ = ret;
347352
self.outputStream.write(self.writer(ret) + '\n');
348353
}

test/parallel/test-repl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ function error_test() {
189189
{ client: client_unix, send: 'url.format("http://google.com")',
190190
expect: 'http://google.com/' },
191191
{ client: client_unix, send: 'var path = 42; path',
192-
expect: '42' }
192+
expect: '42' },
193+
// this makes sure that we don't print `undefined` when we actually print
194+
// the error message
195+
{ client: client_unix, send: '.invalid_repl_command',
196+
expect: 'Invalid REPL keyword\n' + prompt_unix },
193197
]);
194198
}
195199

0 commit comments

Comments
 (0)