diff options
| author | bors <bors@rust-lang.org> | 2014-03-22 08:36:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-03-22 08:36:50 -0700 |
| commit | 5e8e1b515a9ef1cd38ee0c71f032415906a7f42d (patch) | |
| tree | e7003afab13be48f15f121a8dd04e47d938a06d4 | |
| parent | e233a43f5a0e14ceb322b955b16c8967adb2f4a8 (diff) | |
| parent | cffe9e041dc62b98ac83f34c78128febda3d6122 (diff) | |
| download | rust-5e8e1b515a9ef1cd38ee0c71f032415906a7f42d.tar.gz rust-5e8e1b515a9ef1cd38ee0c71f032415906a7f42d.zip | |
auto merge of #13078 : klutzy/rust/issue-13075, r=alexcrichton
`FormatMessageW()` is called by `std::os::last_os_error()` to convert errno into string, but the function may fail on non-english locale. I don't know why it fails, but anyway it's better to return errno than to `fail!()` in the case. Fixes #13075 Fixes #13073
| -rw-r--r-- | src/libstd/os.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index d03757c1e69..f270c7e7a74 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -740,11 +740,16 @@ pub fn last_os_error() -> ~str { buf.len() as DWORD, ptr::null()); if res == 0 { - fail!("[{}] FormatMessage failure", errno()); + // Sometimes FormatMessageW can fail e.g. system doesn't like langId, + let fm_err = errno(); + return format!("OS Error {} (FormatMessageW() returned error {})", err, fm_err); } - str::from_utf16(str::truncate_utf16_at_nul(buf)) - .expect("FormatMessageW returned invalid UTF-16") + let msg = str::from_utf16(str::truncate_utf16_at_nul(buf)); + match msg { + Some(msg) => format!("OS Error {}: {}", err, msg), + None => format!("OS Error {} (FormatMessageW() returned invalid UTF-16)", err), + } } } |
