Skip to content

Commit

Permalink
Fix REPL when it receives EOF (denoland#2638)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jul 12, 2019
1 parent abe8a11 commit 1fde15c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/deno_error.rs
Expand Up @@ -8,6 +8,7 @@ use deno::ErrBox;
use deno::ModuleResolutionError;
use http::uri;
use hyper;
use rustyline::error::ReadlineError;
use std;
use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -185,6 +186,19 @@ impl GetErrorKind for hyper::Error {
}
}

impl GetErrorKind for ReadlineError {
fn kind(&self) -> ErrorKind {
use ReadlineError::*;
match self {
Io(err) => GetErrorKind::kind(err),
Eof => ErrorKind::UnexpectedEof,
#[cfg(unix)]
Errno(err) => err.kind(),
_ => unimplemented!(),
}
}
}

#[cfg(unix)]
mod unix {
use super::{ErrorKind, GetErrorKind};
Expand Down Expand Up @@ -230,6 +244,7 @@ impl GetErrorKind for dyn AnyError {
.or_else(|| self.downcast_ref::<StaticError>().map(Get::kind))
.or_else(|| self.downcast_ref::<uri::InvalidUri>().map(Get::kind))
.or_else(|| self.downcast_ref::<url::ParseError>().map(Get::kind))
.or_else(|| self.downcast_ref::<ReadlineError>().map(Get::kind))
.or_else(|| unix_error_kind(self))
.unwrap_or_else(|| {
panic!("Can't get ErrorKind for {:?}", self);
Expand Down
6 changes: 6 additions & 0 deletions tools/repl_test.py
Expand Up @@ -38,6 +38,12 @@ def test_console_log(self):
self.assertEqual(err, '')
self.assertEqual(code, 0)

def test_eof(self):
out, err, code = self.input("1 + 2", exit=False)
self.assertEqual(out, '3\n')
self.assertEqual(err, '')
self.assertEqual(code, 0)

def test_exit_command(self):
out, err, code = self.input("exit", "'ignored'", exit=False)
self.assertEqual(out, '')
Expand Down

0 comments on commit 1fde15c

Please sign in to comment.