about summary refs log tree commit diff
path: root/library/std/src/io/error.rs
AgeCommit message (Collapse)AuthorLines
2022-10-14Add some tidy-alphabeticalnils-1/+2
2022-10-14Tweak grammarJosh Triplett-1/+1
2022-10-07Improved documentation for `std::io::Error`StackOverflowExcept1on-1/+2
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-08-28Rollup merge of #100296 - BlackHoleFox:os-error-aliases, r=thomccMatthias Krüger-0/+2
Add standard C error function aliases to last_os_error This aids the discoverability of `io::Error::last_os_error()` by linking to commonly used error number functions from C/C++. I've seen a few people not realize this exists, so hopefully this helps draw attention to the API to encourage using it over integer error codes.
2022-08-22Move error trait into coreJane Losare-Lusby-0/+9
2022-08-08Add standard C error function aliasesBlackHoleFox-0/+2
Aids the discoverability of `io::Error::last_os_error()` by linking to commonly used error number functions from C/C++.
2022-07-15Apply suggestions from code reviewJane Losare-Lusby-1/+1
2022-07-15Improve example of `downcast`Jiahao XU-3/+4
Co-authored-by: Jane Losare-Lusby <jlusby42@gmail.com>
2022-07-14Rename `std::io::Error::try_downcast_inner` to `downcast`Jiahao XU-4/+4
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-23Use `unwrap` instead of `unwrap_unchecked`Jiahao XU-3/+7
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-06-22Add new unstable API `Error::try_downgrade_inner`Jiahao XU-0/+57
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-7/+7
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-24word wrpaDylan DPC-5/+5
2022-02-24word wrpaDylan DPC-6/+9
2022-02-23Update library/std/src/io/error.rsDylan DPC-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-23add some more summary from pr discussionDylan DPC-1/+1
2022-02-23add some more summary from pr discussionDylan DPC-2/+4
2022-02-23add matching to errorkindDylan DPC-0/+8
2022-02-10Rename to `InvalidFilename`Yuki Okushi-5/+4
2022-02-10Fix description of FilenameInvalidJosh Triplett-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-02-10Rename `FilenameTooLong` to `FilenameInvalid`Yuki Okushi-2/+2
2022-02-04Add more tests for io::Error packing, and fix some comments that weren't ↵Thom Chiovoloni-0/+4
quite accurate anymore
2022-02-04Update documentation somewhatThom Chiovoloni-0/+10
2022-02-04Elaborate some in the documentation and respond to some review commentsThom Chiovoloni-1/+0
2022-02-04Address address comments, improve comments slightlyThom Chiovoloni-0/+7
2022-02-04Optimize io::error::Repr layout on 64 bit targets.Thom Chiovoloni-4/+11
2022-02-04Hide Repr details from io::Error, and rework `io::Error::new_const`.Thom Chiovoloni-65/+95
2022-01-19`impl Display for io::ErrorKind`Joshua Nelson-1/+17
This avoids having to convert from `ErrorKind` to `Error` just to print the error message.
2021-12-14add `io::Error::other` constructorIbraheem Ahmed-0/+27
2021-12-02Document how `last_os_error` should be usedChris Denton-1/+7
2021-11-21Mention std::io::Error::from(ErrorKind) in Error::new() docsGeorg Brandl-0/+6
This conversion is not very discoverable for the cases where an error is required without extra payload.
2021-10-30Add #[must_use] to remaining std functions (A-N)John Kugelman-0/+5
2021-10-11Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, ↵Guillaume Gomez-0/+1
r=joshtriplett Add #[must_use] to from_value conversions I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument. ```rust core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str; std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString; ``` I put a custom note on `from_raw`: ```rust #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { ``` Parent issue: #89692 r? ``@joshtriplett``
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+1
2021-10-10Add #[must_use] to from_value conversionsJohn Kugelman-0/+1
2021-08-24Fix tidyIan Jackson-2/+2
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::ErrorKind: rationalise ordering in main enumIan Jackson-17/+24
It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::Error: alphabeticise the match in as_str()Ian Jackson-5/+6
There was no rationale for the previous ordering. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-03Auto merge of #79965 - ijackson:moreerrnos, r=joshtriplettbors-21/+139
More ErrorKinds for common errnos From the commit message of the main commit here (as revised): ``` There are a number of IO error situations which it would be very useful for Rust code to be able to recognise without having to resort to OS-specific code. Taking some Unix examples, `ENOTEMPTY` and `EXDEV` have obvious recovery strategies. Recently I was surprised to discover that `ENOSPC` came out as `ErrorKind::Other`. Since I am familiar with Unix I reviwed the list of errno values in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html Here, I add those that most clearly seem to be needed. `@CraftSpider` provided information about Windows, and references, which I have tried to take into account. This has to be insta-stable because we can't sensibly have a different set of ErrorKinds depending on a std feature flag. I have *not* added these to the mapping tables for any operating systems other than Unix and Windows. I hope that it is OK to add them now for Unix and Windows now, and maybe add them to other OS's mapping tables as and when someone on that OS is able to consider the situation. I adopted the general principle that it was usually a bad idea to map two distinct error values to the same Rust error code. I notice that this principle is already violated in the case of `EACCES` and `EPERM`, which both map to `PermissionDenied`. I think this was probably a mistake but it would be quite hard to change now, so I don't propose to do anything about that. However, for Windows, there are sometimes different error codes for identical situations. Eg there are WSA* versions of some error codes as well as ERROR_* ones. Also Windows seems to have a great many more erorr codes. I don't know precisely what best practice would be for Windows. ``` <strike> ``` Errno values I wasn't sure about so *haven't* included: EMFILE ENFILE ENOBUFS ENOLCK: These are all fairly Unix-specific resource exhaustion situations. In practice it seemed not very likely to me that anyone would want to handle these differently to `Other`. ENOMEM ERANGE EDOM EOVERFLOW Normally these don't get exposed to the Rust callers I hope. They don't tend to come out of filesystem APIs. EILSEQ Hopefully Rust libraries open files in binary mode and do the converstion in Rust. So Rust code ought not to be exposed to EILSEQ. EIO The range of things that could cause this is troublesome. I found it difficult to describe. I do think it would be useful to add this at some point, because EIO on a filesystem operation is much more serious than most other errors. ENETDOWN I wasn't sure if this was useful or, indeed, if any modern systems use it. ENOEXEC It is not clear to me how a Rust program could respond to this. It seems rather niche. EPROTO ENETRESET ENODATA ENOMSG ENOPROTOOPT ENOSR ENOSTR ETIME ENOTRECOVERABLE EOWNERDEAD EBADMSG EPROTONOSUPPORT EPROTOTYPE EIDRM These are network or STREAMS related errors which I have never in my own Unix programming found the need to do anything with. I think someone who understands these better should be the one to try to find good Rust names and descriptions for them. ENOTTY ENXIO ENODEV EOPNOTSUPP ESRCH EALREADY ECANCELED ECHILD EINPROGRESS These are very hard to get unless you're already doing something very Unix-specific, in which case the raw_os_error interface is probably more suitable than relying on the Rust ErrorKind mapping. EFAULT EBADF These would seem to be the result of application UB. ``` </strike> <i>(omitted errnos are discussed below, especially in https://github.com/rust-lang/rust/pull/79965#issuecomment-810468334)
2021-06-25Restore original ordering of `ErrorKind::Other`.Mara Bos-8/+9
2021-06-20ErrorKind: Add missing full stopsIan Jackson-3/+3
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-20ErrorKind::FilesystemLoop: Generalise dscriptionIan Jackson-3/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind::NotSeekable: Fix reference to File::open()Ian Jackson-1/+1
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Provide many more ErrorKinds, motivated by Unix errnosIan Jackson-0/+116
Rationale for the mappings etc. is extensively discussed in the MR https://github.com/rust-lang/rust/pull/79965 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Reformat the error string tableIan Jackson-21/+22
* Sort alphabetically. * use ErrorKind::*; Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-6/+6
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-10/+24
2021-05-03Correct stability of ErrorKind::OutOfMemoryKornel-1/+1
2021-05-02Add ErrorKind::OutOfMemoryKornel-0/+6