Skip to content

Commit c1d6748

Browse files
benaadamshalter73
authored andcommitted
Use non-returning throw methods (#11782)
1 parent 3039748 commit c1d6748

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/Http1OutputProducer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,16 @@ private void ThrowIfSuffixSent()
722722
{
723723
if (_writeStreamSuffixCalled)
724724
{
725-
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
725+
ThrowSuffixSent();
726726
}
727727
}
728728

729+
[StackTraceHidden]
730+
private static void ThrowSuffixSent()
731+
{
732+
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
733+
}
734+
729735
/// <summary>
730736
/// Holds a byte[] from the pool and a size value. Basically a Memory but guaranteed to be backed by an ArrayPool byte[], so that we know we can return it.
731737
/// </summary>

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,7 @@ public Task CompleteAsync(Exception exception = null)
14421442
// so it can be observed by BodyWriter.Complete(). If this isn't possible because an
14431443
// async OnStarting callback hadn't yet run, it's OK, since the Exception will be observed with
14441444
// the call to _bodyControl.StopAsync() in ProcessRequests().
1445-
throw lengthException;
1445+
ThrowException(lengthException);
14461446
}
14471447

14481448
return ProduceEnd();
@@ -1459,13 +1459,19 @@ private async Task CompleteAsyncAwaited(Task onStartingTask)
14591459
{
14601460
if (!VerifyResponseContentLength(out var lengthException))
14611461
{
1462-
throw lengthException;
1462+
ThrowException(lengthException);
14631463
}
14641464

14651465
await ProduceEnd();
14661466
}
14671467
}
14681468

1469+
[StackTraceHidden]
1470+
private static void ThrowException(Exception exception)
1471+
{
1472+
throw exception;
1473+
}
1474+
14691475
public ValueTask<FlushResult> WritePipeAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
14701476
{
14711477
// For the first write, ensure headers are flushed if WriteDataAsync isn't called.

src/Servers/Kestrel/Core/src/Internal/Http2/Http2OutputProducer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,16 @@ private void ThrowIfSuffixSent()
437437
{
438438
if (_suffixSent)
439439
{
440-
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
440+
ThrowSuffixSent();
441441
}
442442
}
443443

444+
[StackTraceHidden]
445+
private static void ThrowSuffixSent()
446+
{
447+
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
448+
}
449+
444450
private static Pipe CreateDataPipe(MemoryPool<byte> pool)
445451
=> new Pipe(new PipeOptions
446452
(

0 commit comments

Comments
 (0)