-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::io: New ErrorKind value InvalidData #25246
Conversation
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
This is a PR for rust-lang/rfcs#906. |
To bikeshed a bit more, I'd rename |
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably stay as-is. CString::new
returns a NulError
when its argument (input) contains a null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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? |
cc @aturon |
@alexcrichton Other than data format errors, |
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 |
|
#25406 is an alternative change where, conversely, the invalid-parameter cases are reclassified from |
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 |
When we are decoding a stream of text, it's invalid input to the program, not output. |
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). |
cae27c9
to
999ffea
Compare
Following some bikeshedding on PR rust-lang#25246.
I have updated the branch, thanks for your input. In my personal opinion, there is still potential for confusion between |
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? 😄 InvalidParameter, InvalidArgument, anything like that is better. W.r.t if data we process using the APIs is regarded as output from something else or input to us, or the reverse, that I don't know. I suggest just saying data for that, hence InvalidData. |
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. |
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 |
I would be happier. Consider that we use |
999ffea
to
7d50cbc
Compare
Rebased and condensed into one commit. |
@@ -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")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have copy-pasted it without thinking.
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.
7d50cbc
to
1d67cef
Compare
Updated and rebased the commit, now with a more descriptive doc text and corrected stability attribute. |
/// 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")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
Note that this is, strictly speaking, a breaking change: error-handling code that matches for |
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. Fixes rust-lang/rfcs#906
💔 Test failed - auto-linux-64-opt |
@bors: retry On Mon, Jun 1, 2015 at 11:57 AM, bors notifications@github.com wrote:
|
⚡ Previous build results for auto-linux-32-nopt-t, auto-linux-64-nopt-t, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-gnu-32-nopt-t, auto-win-gnu-32-opt, auto-win-gnu-64-nopt-t, auto-win-gnu-64-opt are reusable. Rebuilding only auto-linux-32-opt, auto-linux-64-opt... |
@bors: retry clean force |
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. Fixes rust-lang/rfcs#906
This takes the cases from
InvalidInput
where 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