mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-24 04:01:07 +03:00
Convert IntervalSet from throwing exceptions to using CHECKs with Expected error handling
Summary: This commit converts IntervalSet to use CHECKs instead of throwing exceptions and provides safe tryInsert methods that return quic::Expected for error handling. **Core Problem Solved:** IntervalSet was throwing `std::invalid_argument` exceptions in two scenarios: 1. When constructing an Interval with `start > end` 2. When interval bounds exceed the maximum allowed value This change eliminates exceptions in favor of CHECKs (for internal validation) and Expected-based error handling (for caller validation). **Implementation Details:** **1. IntervalSet Core Changes:** - Replaced `throw std::invalid_argument` with `CHECK_LE` in Interval constructor - Replaced `throw std::invalid_argument` with `CHECK_LE` in `insert(start, end)` - Added `IntervalSetError` enum for error classification - Added `folly::Expected` include **2. Safe API Layer:** - Added `tryInsert(interval)` method returning `Expected<Unit, IntervalSetError>` - Added `tryInsert(start, end)` method with pre-validation - Added `tryInsert(point)` method - Added static `Interval::tryCreate()` method for safe interval construction **3. Updated Code:** - **QuicWriteCodec.cpp**: Updated `fillFrameWithPacketReceiveTimestamps` to use `tryInsert` - Returns `QuicError` if interval validation fails - Maintains existing error handling patterns - **QuicTransportFunctions.cpp**: Updated `implicitAckCryptoStream` to use `tryInsert` - Logs errors and continues processing other packets - Robust error handling for crypto stream implicit acks Reviewed By: kvtsoy Differential Revision: D76792362 fbshipit-source-id: 5bd7c22e69a91d60cc41c603a1f2380893f4c8a0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8f8be8d5d0
commit
d3e8fe246a
@@ -345,7 +345,7 @@ TEST_F(QuicResetSentStateTest, ReliableRstAckNoReduction) {
|
||||
stream.readBuffer.emplace_back(
|
||||
folly::IOBuf::copyBuffer("One more thing"), 0xABCD, false);
|
||||
RstStreamFrame frame(id, GenericApplicationErrorCode::UNKNOWN, 0);
|
||||
stream.updateAckedIntervals(0, 3, false);
|
||||
ASSERT_TRUE(stream.updateAckedIntervals(0, 3, false).has_value());
|
||||
auto result = sendRstAckSMHandler(stream, 5);
|
||||
ASSERT_FALSE(result.hasError());
|
||||
|
||||
@@ -370,7 +370,7 @@ TEST_F(QuicResetSentStateTest, ReliableRstAckReduction) {
|
||||
stream.readBuffer.emplace_back(
|
||||
folly::IOBuf::copyBuffer("One more thing"), 0xABCD, false);
|
||||
RstStreamFrame frame(id, GenericApplicationErrorCode::UNKNOWN, 0);
|
||||
stream.updateAckedIntervals(0, 1, false);
|
||||
ASSERT_TRUE(stream.updateAckedIntervals(0, 1, false).has_value());
|
||||
auto result = sendRstAckSMHandler(stream, 1);
|
||||
ASSERT_FALSE(result.hasError());
|
||||
|
||||
@@ -434,7 +434,7 @@ TEST_F(QuicResetSentStateTest, ResetSentToClosedTransition1) {
|
||||
StreamId id = 5;
|
||||
QuicStreamState stream(id, *conn);
|
||||
stream.sendState = StreamSendState::ResetSent;
|
||||
stream.updateAckedIntervals(0, 5, false);
|
||||
ASSERT_TRUE(stream.updateAckedIntervals(0, 5, false).has_value());
|
||||
auto result = sendRstAckSMHandler(stream, 5);
|
||||
ASSERT_FALSE(result.hasError());
|
||||
EXPECT_EQ(stream.sendState, StreamSendState::Closed);
|
||||
@@ -447,7 +447,7 @@ TEST_F(QuicResetSentStateTest, ResetSentToClosedTransition2) {
|
||||
StreamId id = 5;
|
||||
QuicStreamState stream(id, *conn);
|
||||
stream.sendState = StreamSendState::ResetSent;
|
||||
stream.updateAckedIntervals(0, 4, false);
|
||||
ASSERT_TRUE(stream.updateAckedIntervals(0, 4, false).has_value());
|
||||
auto result = sendRstAckSMHandler(stream, 5);
|
||||
ASSERT_FALSE(result.hasError());
|
||||
EXPECT_EQ(stream.sendState, StreamSendState::ResetSent);
|
||||
|
||||
Reference in New Issue
Block a user