Handle ENOENT
Translate ENOENT to IoErrorKind::FileNotFound.
This commit is contained in:
@@ -337,6 +337,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
|
|||||||
EACCES => PermissionDenied,
|
EACCES => PermissionDenied,
|
||||||
ECONNREFUSED => ConnectionRefused,
|
ECONNREFUSED => ConnectionRefused,
|
||||||
ECONNRESET => ConnectionReset,
|
ECONNRESET => ConnectionReset,
|
||||||
|
ENOENT => FileNotFound,
|
||||||
ENOTCONN => NotConnected,
|
ENOTCONN => NotConnected,
|
||||||
EPIPE => BrokenPipe,
|
EPIPE => BrokenPipe,
|
||||||
ECONNABORTED => ConnectionAborted,
|
ECONNABORTED => ConnectionAborted,
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub static EOF: c_int = -4095;
|
|||||||
pub static UNKNOWN: c_int = -4094;
|
pub static UNKNOWN: c_int = -4094;
|
||||||
|
|
||||||
// uv-errno.h redefines error codes for windows, but not for unix...
|
// uv-errno.h redefines error codes for windows, but not for unix...
|
||||||
|
// https://github.com/joyent/libuv/blob/master/include/uv-errno.h
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub mod errors {
|
pub mod errors {
|
||||||
@@ -52,6 +53,7 @@ pub mod errors {
|
|||||||
pub static EACCES: c_int = -4092;
|
pub static EACCES: c_int = -4092;
|
||||||
pub static ECONNREFUSED: c_int = -4078;
|
pub static ECONNREFUSED: c_int = -4078;
|
||||||
pub static ECONNRESET: c_int = -4077;
|
pub static ECONNRESET: c_int = -4077;
|
||||||
|
pub static ENOENT: c_int = -4058;
|
||||||
pub static ENOTCONN: c_int = -4053;
|
pub static ENOTCONN: c_int = -4053;
|
||||||
pub static EPIPE: c_int = -4047;
|
pub static EPIPE: c_int = -4047;
|
||||||
pub static ECONNABORTED: c_int = -4079;
|
pub static ECONNABORTED: c_int = -4079;
|
||||||
@@ -66,6 +68,7 @@ pub mod errors {
|
|||||||
pub static EACCES: c_int = -libc::EACCES;
|
pub static EACCES: c_int = -libc::EACCES;
|
||||||
pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
|
pub static ECONNREFUSED: c_int = -libc::ECONNREFUSED;
|
||||||
pub static ECONNRESET: c_int = -libc::ECONNRESET;
|
pub static ECONNRESET: c_int = -libc::ECONNRESET;
|
||||||
|
pub static ENOENT: c_int = -libc::ENOENT;
|
||||||
pub static ENOTCONN: c_int = -libc::ENOTCONN;
|
pub static ENOTCONN: c_int = -libc::ENOTCONN;
|
||||||
pub static EPIPE: c_int = -libc::EPIPE;
|
pub static EPIPE: c_int = -libc::EPIPE;
|
||||||
pub static ECONNABORTED: c_int = -libc::ECONNABORTED;
|
pub static ECONNABORTED: c_int = -libc::ECONNABORTED;
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ mod tests {
|
|||||||
do run_in_mt_newsched_task {
|
do run_in_mt_newsched_task {
|
||||||
let mut called = false;
|
let mut called = false;
|
||||||
io_error::cond.trap(|e| {
|
io_error::cond.trap(|e| {
|
||||||
assert_eq!(e.kind, OtherIoError);
|
assert_eq!(e.kind, FileNotFound);
|
||||||
called = true;
|
called = true;
|
||||||
}).inside(|| {
|
}).inside(|| {
|
||||||
let stream = UnixStream::connect(&("path/to/nowhere"));
|
let stream = UnixStream::connect(&("path/to/nowhere"));
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ mod tests {
|
|||||||
use task::spawn;
|
use task::spawn;
|
||||||
use unstable::running_on_valgrind;
|
use unstable::running_on_valgrind;
|
||||||
use io::native::file;
|
use io::native::file;
|
||||||
use io::{Writer, Reader, io_error};
|
use io::{FileNotFound, OtherIoError, Reader, Writer, io_error};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os="android"))] // FIXME(#10380)
|
#[cfg(not(target_os="android"))] // FIXME(#10380)
|
||||||
@@ -354,9 +354,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_output_fail_to_start() {
|
fn test_process_output_fail_to_start() {
|
||||||
|
// If the executable does not exist, then the io_error condition should be raised with
|
||||||
|
// IoErrorKind FileNotFound.
|
||||||
|
|
||||||
let mut trapped_io_error = false;
|
let mut trapped_io_error = false;
|
||||||
let opt_outp = io_error::cond.trap(|_| {
|
let opt_outp = io_error::cond.trap(|e| {
|
||||||
trapped_io_error = true;
|
trapped_io_error = true;
|
||||||
|
// FIXME(#11023)
|
||||||
|
assert_eq!(e.kind, if cfg!(windows) { OtherIoError } else { FileNotFound });
|
||||||
}).inside(|| -> Option<run::ProcessOutput> {
|
}).inside(|| -> Option<run::ProcessOutput> {
|
||||||
run::process_output("no-binary-by-this-name-should-exist", [])
|
run::process_output("no-binary-by-this-name-should-exist", [])
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user