From 1fde15c0bc77e0c5cc6f7cbf27b4e072e1ad6c46 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 12 Jul 2019 10:23:08 -0400 Subject: [PATCH] Fix REPL when it receives EOF (#2638) --- cli/deno_error.rs | 15 +++++++++++++++ tools/repl_test.py | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/cli/deno_error.rs b/cli/deno_error.rs index 717924701a..544a411bac 100644 --- a/cli/deno_error.rs +++ b/cli/deno_error.rs @@ -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; @@ -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}; @@ -230,6 +244,7 @@ impl GetErrorKind for dyn AnyError { .or_else(|| self.downcast_ref::().map(Get::kind)) .or_else(|| self.downcast_ref::().map(Get::kind)) .or_else(|| self.downcast_ref::().map(Get::kind)) + .or_else(|| self.downcast_ref::().map(Get::kind)) .or_else(|| unix_error_kind(self)) .unwrap_or_else(|| { panic!("Can't get ErrorKind for {:?}", self); diff --git a/tools/repl_test.py b/tools/repl_test.py index e8b1f1a6f3..5ad7722ee1 100644 --- a/tools/repl_test.py +++ b/tools/repl_test.py @@ -38,6 +38,12 @@ class TestRepl(DenoTestCase): 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, '')