kubkon opened PR #1243 from winx-io-error
to master
:
This commit is a spiritual follower of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
kubkon requested peterhuene, marmistrz, and sunfishcode for a review on PR #1243.
kubkon requested peterhuene, marmistrz, and sunfishcode for a review on PR #1243.
kubkon requested peterhuene, marmistrz, and sunfishcode for a review on PR #1243.
kubkon updated PR #1243 from winx-io-error
to master
:
This commit is a spiritual follower of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
kubkon edited PR #1243 from winx-io-error
to master
:
This commit is a spiritual descendant of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
kubkon edited PR #1243 from winx-io-error
to master
:
This commit is a spiritual successor of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
Or even better yet:
fn extract_raw_os_error(e: io::Error) -> Result<i32> { // match returning EIO for "other errors" } let err = match fs::rename(...) { Ok(()) => return Ok(()), Err(e) => extract_raw_os_error(e)?, }; // de-indented error-handling code ~~~
alexcrichton created PR Review Comment:
FWIW this'd probably be a good place to do something like:
let err = match fs::rename(...) { Ok(()) => return Ok(()), Err(e) => e, }; // de-indented error-handling code ~~~
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
One thing I've found helpful personally is to consistently use the same error handling pattern, e.g. using
match
everywhere or usingmap_err
everywhere. (I realize this is existing code so don't put too much weight on this, just wanted to leave a passing comment about this)Basically I think it'd be better to use the same idioms here (not
map_err
) to handle errors as elsewhere.
kubkon created PR Review Comment:
Nice, I like it! I'll try and enforce this principle whenever I write similar code in the future. Also, while I won't do this in this PR, when I'm less creative I might scan
wasi-common
and related, and rewrite any suitable occurrence using this principle. :+1:
kubkon submitted PR Review.
kubkon created PR Review Comment:
Oh oops, the reply to the above should have been written down here actually.
kubkon submitted PR Review.
kubkon edited PR Review Comment.
kubkon updated PR #1243 from winx-io-error
to master
:
This commit is a spiritual successor of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
kubkon updated PR #1243 from winx-io-error
to master
:
This commit is a spiritual successor of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
alexcrichton submitted PR Review.
kubkon updated PR #1243 from winx-io-error
to master
:
This commit is a spiritual successor of #1242 in the sense that it adjusts
winx
to also returnio::Error
directly rather than tossing a custom error type here and there.While here, I've also done a little bit of refactoring as suggested by @alexcrichton in #1226: whenever we re-map error values, just use plain old
match
(orif let
), and do early returns.
marmistrz submitted PR Review.
marmistrz submitted PR Review.
marmistrz created PR Review Comment:
I'd say that
or_else
is more readable
marmistrz created PR Review Comment:
Will this conversion always succeed?
marmistrz created PR Review Comment:
Are you sure that you want to modify the snapshot?
marmistrz created PR Review Comment:
I'd say that without
return
s the control flow is easier to follow.
marmistrz created PR Review Comment:
How about adding a comment why unwrap will always succeed (possibly using expect)?
kubkon submitted PR Review.
kubkon created PR Review Comment:
AFAIK, on Windows,
io::Error
populated with raw OS error (as is the case here) will never store a value that's negative sinceGetLastError()
always returns aDWORD
akau32
. So the only case when this case would silently fail would be ifcode
value had overflownu32
which is impossible given thatio::Error::from_raw_os_error(code: i32)
expects ani32
as its argument. Also, it's worth noting that this approach matches that of Rust'slibstd
, so I think we should be safe here.
kubkon submitted PR Review.
kubkon created PR Review Comment:
Hmm, I actually have to agree with @alexcrichton on this one, and prefer explicit
match
/if let
with early returns.
kubkon submitted PR Review.
kubkon created PR Review Comment:
See above :-)
kubkon submitted PR Review.
kubkon created PR Review Comment:
The changes to the snapshot do not touch either its use of the WASI ABI nor the functional aspects of the code which are identical between both snapshots anyhow, so we're fine here.
kubkon submitted PR Review.
kubkon created PR Review Comment:
See discussion in #1242, plus raw_os_error docs.
marmistrz submitted PR Review.
kubkon merged PR #1243.
Last updated: Dec 23 2024 at 13:07 UTC