Use non-returning throw methods (#11782)

This commit is contained in:
Ben Adams 2019-07-18 22:36:11 +01:00 committed by Stephen Halter
parent 3039748ccf
commit c1d6748c5b
3 changed files with 22 additions and 4 deletions

View File

@ -722,10 +722,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
if (_writeStreamSuffixCalled) if (_writeStreamSuffixCalled)
{ {
throw new InvalidOperationException("Writing is not allowed after writer was completed."); ThrowSuffixSent();
} }
} }
[StackTraceHidden]
private static void ThrowSuffixSent()
{
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
}
/// <summary> /// <summary>
/// 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. /// 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.
/// </summary> /// </summary>

View File

@ -1442,7 +1442,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
// so it can be observed by BodyWriter.Complete(). If this isn't possible because an // so it can be observed by BodyWriter.Complete(). If this isn't possible because an
// async OnStarting callback hadn't yet run, it's OK, since the Exception will be observed with // async OnStarting callback hadn't yet run, it's OK, since the Exception will be observed with
// the call to _bodyControl.StopAsync() in ProcessRequests(). // the call to _bodyControl.StopAsync() in ProcessRequests().
throw lengthException; ThrowException(lengthException);
} }
return ProduceEnd(); return ProduceEnd();
@ -1459,13 +1459,19 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
{ {
if (!VerifyResponseContentLength(out var lengthException)) if (!VerifyResponseContentLength(out var lengthException))
{ {
throw lengthException; ThrowException(lengthException);
} }
await ProduceEnd(); await ProduceEnd();
} }
} }
[StackTraceHidden]
private static void ThrowException(Exception exception)
{
throw exception;
}
public ValueTask<FlushResult> WritePipeAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken) public ValueTask<FlushResult> WritePipeAsync(ReadOnlyMemory<byte> data, CancellationToken cancellationToken)
{ {
// For the first write, ensure headers are flushed if WriteDataAsync isn't called. // For the first write, ensure headers are flushed if WriteDataAsync isn't called.

View File

@ -437,10 +437,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
if (_suffixSent) if (_suffixSent)
{ {
throw new InvalidOperationException("Writing is not allowed after writer was completed."); ThrowSuffixSent();
} }
} }
[StackTraceHidden]
private static void ThrowSuffixSent()
{
throw new InvalidOperationException("Writing is not allowed after writer was completed.");
}
private static Pipe CreateDataPipe(MemoryPool<byte> pool) private static Pipe CreateDataPipe(MemoryPool<byte> pool)
=> new Pipe(new PipeOptions => new Pipe(new PipeOptions
( (