Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstd::io: New ErrorKind value InvalidData #25246
Conversation
rust-highfive
assigned
pcwalton
May 9, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
This is a PR for rust-lang/rfcs#906. |
This comment has been minimized.
This comment has been minimized.
|
To bikeshed a bit more, I'd rename |
Stebalien
reviewed
May 11, 2015
| @@ -239,7 +239,7 @@ impl fmt::Display for NulError { | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| impl From<NulError> for io::Error { | |||
| fn from(_: NulError) -> io::Error { | |||
| io::Error::new(io::ErrorKind::InvalidInput, | |||
| io::Error::new(io::ErrorKind::InvalidData, | |||
This comment has been minimized.
This comment has been minimized.
Stebalien
May 11, 2015
Contributor
This should probably stay as-is. CString::new returns a NulError when its argument (input) contains a null.
This comment has been minimized.
This comment has been minimized.
mzabaluev
May 13, 2015
Author
Contributor
The character data may have come from outside the program. In general, it's not a programming error for strings to contain null bytes, so to me it belongs in the same class of data conversion failures as, say, encountering malformed UTF-8 in an input operation that reads to a string.
This comment has been minimized.
This comment has been minimized.
|
I'm not sure I personally understand the distinction here, it seems like selecting one or the other can be ambiguous from time to time and the distinction may not actually carry much weight in the wild. Could you elaborate a little more on how these two are distinct and how they should be interpreted separately? |
alexcrichton
assigned
alexcrichton
and unassigned
pcwalton
May 12, 2015
This comment has been minimized.
This comment has been minimized.
|
cc @aturon |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Other than data format errors, |
This comment has been minimized.
This comment has been minimized.
|
Hm I guess to me those seem like very similar classes of errors as they're both "invalid inputs" to the function. I think that |
This comment has been minimized.
This comment has been minimized.
|
|
mzabaluev
referenced this pull request
May 14, 2015
Closed
std::io: new ErrorKind value InvalidParam #25406
This comment has been minimized.
This comment has been minimized.
|
#25406 is an alternative change where, conversely, the invalid-parameter cases are reclassified from |
This comment has been minimized.
This comment has been minimized.
|
FWIW, I agree that it would be good to have distinct errors for "You passed in arguments that broke the contract" versus "The OS returned some data that was not in the expected form". I'm not in love with I also agree with others that the |
This comment has been minimized.
This comment has been minimized.
When we are decoding a stream of text, it's invalid input to the program, not output. |
This comment has been minimized.
This comment has been minimized.
The error variant is relative to the operation being performed, not the broader context of the program. We need the pair of variants to clearly signify whether the problem was with the arguments passed to the operation (InvalidInput) or with the data produced by the operation (hence InvalidOutput). |
mzabaluev
force-pushed the
mzabaluev:io-invalid-data
branch
from
cae27c9
to
999ffea
May 17, 2015
mzabaluev
added a commit
to mzabaluev/rust
that referenced
this pull request
May 17, 2015
This comment has been minimized.
This comment has been minimized.
|
I have updated the branch, thanks for your input. In my personal opinion, there is still potential for confusion between |
This comment has been minimized.
This comment has been minimized.
|
My head is spinning. Run this past a bit more people to see what they think? Why do we use the terms Input / Output when we don't mean I/O? |
This comment has been minimized.
This comment has been minimized.
|
The usage here is just the notion of arguments being "input" to a function, and the results it produces being its "output". Admittedly, InvalidArgument and InvalidResult would probably be more clear, but that would require a breaking change. |
This comment has been minimized.
This comment has been minimized.
|
OK, after talking to @alexcrichton for a while, and stewing a bit more on the comments here, I think @bluss is right and the names |
This comment has been minimized.
This comment has been minimized.
|
I would be happier. Consider that we use |
mzabaluev
force-pushed the
mzabaluev:io-invalid-data
branch
from
999ffea
to
7d50cbc
May 21, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased and condensed into one commit. |
alexcrichton
reviewed
May 26, 2015
| @@ -95,6 +95,9 @@ pub enum ErrorKind { | |||
| /// A parameter was incorrect. | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| InvalidInput, | |||
| /// Invalid data encountered. | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 26, 2015
Member
This stability tag should now say 1.1.0, and the feature name can be something like io_invalid_data.
Could you also expand the docs here a bit to clarify what InvalidData means with respect to InvalidInput?
This comment has been minimized.
This comment has been minimized.
alexcrichton
added
the
T-libs
label
May 26, 2015
mzabaluev
force-pushed the
mzabaluev:io-invalid-data
branch
from
7d50cbc
to
1d67cef
May 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated and rebased the commit, now with a more descriptive doc text and corrected stability attribute. |
alexcrichton
reviewed
May 29, 2015
| /// 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")] |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 29, 2015
Member
Gah oops, sorry but I forgot we've entered 1.2 territory at this point, so this should actually be 1.2 instead of 1.1. Other than that though this looks good to me!
This comment has been minimized.
This comment has been minimized.
|
Note that this is, strictly speaking, a breaking change: error-handling code that matches for |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jun 1, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Mon, Jun 1, 2015 at 11:57 AM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry clean force |
mzabaluev commentedMay 9, 2015
This takes the cases from
InvalidInputwhere a data format errorwas encountered. This is different from the documented semantics
of
InvalidInput, which more likely indicate a programming error.Fixes rust-lang/rfcs#906