Skip to content

Commit f01bb79

Browse files
committed
refactor: drop string from SpuriousRateLimiterEvent error variant
The variant was only constructed in a single place, so just make the string that was passed there the display text for this error. Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent 4a21dc6 commit f01bb79

File tree

1 file changed

+8
-10
lines changed
  • src/vmm/src/rate_limiter

1 file changed

+8
-10
lines changed

src/vmm/src/rate_limiter/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub mod persist;
1212
#[derive(Debug, thiserror::Error, displaydoc::Display)]
1313
/// Describes the errors that may occur while handling rate limiter events.
1414
pub enum RateLimiterError {
15-
/// The event handler was called spuriously: {0}
16-
SpuriousRateLimiterEvent(&'static str),
15+
/// Rate limiter event handler called without a present timer
16+
SpuriousRateLimiterEvent,
1717
}
1818

1919
// Interval at which the refill timer will run when limiter is at capacity.
@@ -470,9 +470,7 @@ impl RateLimiter {
470470
/// If the rate limiter is disabled or is not blocked, an error is returned.
471471
pub fn event_handler(&mut self) -> Result<(), RateLimiterError> {
472472
match self.timer_fd.read() {
473-
0 => Err(RateLimiterError::SpuriousRateLimiterEvent(
474-
"Rate limiter event handler called without a present timer",
475-
)),
473+
0 => Err(RateLimiterError::SpuriousRateLimiterEvent),
476474
_ => {
477475
self.timer_active = false;
478476
Ok(())
@@ -950,11 +948,11 @@ pub(crate) mod tests {
950948
assert!(l.consume(u64::MAX, TokenType::Ops));
951949
assert!(l.consume(u64::MAX, TokenType::Bytes));
952950
// calling the handler without there having been an event should error
953-
l.event_handler().unwrap_err();
954-
assert_eq!(
955-
format!("{:?}", l.event_handler().err().unwrap()),
956-
"SpuriousRateLimiterEvent(\"Rate limiter event handler called without a present \
957-
timer\")"
951+
let err = l.event_handler().unwrap_err();
952+
assert!(
953+
matches!(err, RateLimiterError::SpuriousRateLimiterEvent),
954+
"{:?}",
955+
err
958956
);
959957
}
960958

0 commit comments

Comments
 (0)