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:
parent
abe8a113ad
commit
1fde15c0bc
2 changed files with 21 additions and 0 deletions
|
@ -8,6 +8,7 @@ use deno::ErrBox;
|
||||||
use deno::ModuleResolutionError;
|
use deno::ModuleResolutionError;
|
||||||
use http::uri;
|
use http::uri;
|
||||||
use hyper;
|
use hyper;
|
||||||
|
use rustyline::error::ReadlineError;
|
||||||
use std;
|
use std;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
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)]
|
#[cfg(unix)]
|
||||||
mod unix {
|
mod unix {
|
||||||
use super::{ErrorKind, GetErrorKind};
|
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::<StaticError>().map(Get::kind))
|
||||||
.or_else(|| self.downcast_ref::<uri::InvalidUri>().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::<url::ParseError>().map(Get::kind))
|
||||||
|
.or_else(|| self.downcast_ref::<ReadlineError>().map(Get::kind))
|
||||||
.or_else(|| unix_error_kind(self))
|
.or_else(|| unix_error_kind(self))
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
panic!("Can't get ErrorKind for {:?}", self);
|
panic!("Can't get ErrorKind for {:?}", self);
|
||||||
|
|
|
@ -38,6 +38,12 @@ class TestRepl(DenoTestCase):
|
||||||
self.assertEqual(err, '')
|
self.assertEqual(err, '')
|
||||||
self.assertEqual(code, 0)
|
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):
|
def test_exit_command(self):
|
||||||
out, err, code = self.input("exit", "'ignored'", exit=False)
|
out, err, code = self.input("exit", "'ignored'", exit=False)
|
||||||
self.assertEqual(out, '')
|
self.assertEqual(out, '')
|
||||||
|
|
Loading…
Reference in a new issue