From 1d67cef6d2791511c467ea330cb54660e6aa703d Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Sat, 9 May 2015 18:57:26 +0300 Subject: [PATCH 1/2] std::io: New ErrorKind value InvalidData This takes the cases from InvalidInput where a data format error was encountered. This is different from the documented semantics of InvalidInput, which more likely indicate a programming error. --- src/libstd/io/error.rs | 7 +++++++ src/libstd/io/mod.rs | 2 +- src/libstd/sys/windows/stdio.rs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 85b957640fdab..92b5fab6df210 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -95,6 +95,13 @@ pub enum ErrorKind { /// A parameter was incorrect. #[stable(feature = "rust1", since = "1.0.0")] InvalidInput, + /// Data not valid for the operation were encountered. + /// + /// Unlike `InvalidInput`, this typically means that the operation + /// parameters were valid, however the error was caused by malformed + /// input data. + #[stable(feature = "io_invalid_data", since = "1.1.0")] + InvalidData, /// The I/O operation's timeout expired, causing it to be canceled. #[stable(feature = "rust1", since = "1.0.0")] TimedOut, diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index c664def304e09..3d0dfbba0ab99 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -80,7 +80,7 @@ fn append_to_string(buf: &mut String, f: F) -> Result let ret = f(g.s); if str::from_utf8(&g.s[g.len..]).is_err() { ret.and_then(|_| { - Err(Error::new(ErrorKind::InvalidInput, + Err(Error::new(ErrorKind::InvalidData, "stream did not contain valid UTF-8")) }) } else { diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 03547165f5d87..e56722a189d7e 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -170,5 +170,5 @@ impl Output { } fn invalid_encoding() -> io::Error { - io::Error::new(io::ErrorKind::InvalidInput, "text was not valid unicode") + io::Error::new(io::ErrorKind::InvalidData, "text was not valid unicode") } From 0ad019f4e86d68682dacb90f1d0d03cddba31bac Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Sat, 30 May 2015 15:09:13 +0300 Subject: [PATCH 2/2] std::io: bump the stability tag on ErrorKind::InvalidData to 1.2.0 --- src/libstd/io/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 92b5fab6df210..c4e472f158edf 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -100,7 +100,7 @@ pub enum ErrorKind { /// Unlike `InvalidInput`, this typically means that the operation /// parameters were valid, however the error was caused by malformed /// input data. - #[stable(feature = "io_invalid_data", since = "1.1.0")] + #[stable(feature = "io_invalid_data", since = "1.2.0")] InvalidData, /// The I/O operation's timeout expired, causing it to be canceled. #[stable(feature = "rust1", since = "1.0.0")]