1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Fix REPL when it receives EOF (#2638)

This commit is contained in:
Ryan Dahl 2019-07-12 10:23:08 -04:00 committed by GitHub
parent abe8a113ad
commit 1fde15c0bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -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::<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);

View file

@ -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, '')