-
Notifications
You must be signed in to change notification settings - Fork 126
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
chore: Remove some unwrap
s and replace others by expect
#2294
base: main
Are you sure you want to change the base?
Conversation
In functions that return `Result`.
Failed Interop TestsQUIC Interop Runner, client vs. server, differences relative to 4028ca4. neqo-latest as client
neqo-latest as server
All resultsSucceeded Interop TestsQUIC Interop Runner, client vs. server neqo-latest as client
neqo-latest as server
Unsupported Interop TestsQUIC Interop Runner, client vs. server neqo-latest as client
neqo-latest as server
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2294 +/- ##
==========================================
- Coverage 93.33% 93.13% -0.20%
==========================================
Files 114 114
Lines 36896 36931 +35
Branches 36896 36931 +35
==========================================
- Hits 34438 34397 -41
- Misses 1675 1693 +18
- Partials 783 841 +58 ☔ View full report in Codecov by Sentry. |
cf9783c
to
c9f1896
Compare
unwrap
sunwrap
s and replace others by expect
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.
Lots of improvements here, but there are a few places where some of that could be improved.
(Non-blocking comment as I'm going on leave.)
self.secrets.register(self.fd)?; | ||
self.raw = Some(r); | ||
Ok(()) | ||
} else if self.raw.unwrap() == r { | ||
} else if self.raw.ok_or(Error::InternalError)? == r { | ||
Ok(()) |
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 probably needs to be restructured:
if let Some(raw) = self.raw {
if raw == r {
Ok(())
} else {
Err(Error::MixedHandshakeMethod)
}
} else {
self.secrets.register(self.fd)?;
self.raw = Some(r);
Ok(())
}
}
@@ -22,6 +22,7 @@ fn se_create() { | |||
const PLAINTEXT: &[u8] = b"PLAINTEXT"; | |||
const AAD: &[u8] = b"AAD"; | |||
|
|||
#[cfg(test)] |
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 is in tests/
. Why would it need this?
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.
I don't know, but it does. Otherwise clippy complains.
session_id: stream_info.session_id().unwrap(), | ||
}, | ||
)); | ||
if let Some(session_id) = stream_info.session_id() { |
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.
Is this truly safe? It seems like this should always be called with stream info that has a session ID, but what do we do if it doesn't?
.unwrap() | ||
.maybe_update_priority(priority) | ||
let Some(stream) = self.control_stream_recv.http_stream() else { | ||
return false; |
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.
Like the one above.
.unwrap() | ||
.priority_update_sent(); | ||
let Some(stream) = self.control_stream_recv.http_stream() else { | ||
return; |
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.
Same.
write_chunk(offset + mid as u64, right, builder), | ||
write_chunk(offset, left, builder), | ||
] | ||
if let Some(cs) = self.get_mut(space) { |
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.
I think that this would be better with:
let Some(cs) = self.get_mut(space) else { return; }
let Some(primary) = self.migration_target.take() else { | ||
break; |
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.
I think that you can restructure this little piece of code to avoid the extra break.
let Some(primary) = self.migration_target.as_mut() else { break; }
if Rc::ptr_eq(target, primary) {
let p = primary.take();
mem::drop(self.select_primary(&p, now));
return true;
}
break;
Once we're on 1.80 MSRV, we can use Option::take_if
and simplify further.
if let Some(primary) = self.migration_target.take_if(|p| Rc::ptr_eq(target, p))
mem::drop(self.select_primary(&primary, now));
return true;
}
break;
&mut lost, | ||
); | ||
self.stats.borrow_mut().lost += lost.len(); | ||
if let Some(sp) = self.spaces.get_mut(pn_space) { |
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 is another great candidate for let Some(foo) = expr else { return ...; };
@@ -457,7 +457,8 @@ impl TransportParameters { | |||
let rbuf = random::<4>(); | |||
let mut other = Vec::with_capacity(versions.all().len() + 1); | |||
let mut dec = Decoder::new(&rbuf); | |||
let grease = dec.decode_uint::<u32>().unwrap() & 0xf0f0_f0f0 | 0x0a0a_0a0a; | |||
let grease = | |||
dec.decode_uint::<u32>().expect("dec has u32 left") & 0xf0f0_f0f0 | 0x0a0a_0a0a; |
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 is a good place to go with u32::from_ne_bytes(random::<4>)
, like above.
Co-authored-by: Martin Thomson <[email protected]> Signed-off-by: Lars Eggert <[email protected]>
In functions that return
Result
orOption
or where it is easy to make them do so w/o too many other code changes.This lets us enable the clippy
unwrap_used
check, which is a nice reminder not to be casual withunwrap
.