Skip to content

Commit

Permalink
Merge pull request #28 from cuteant/throwhelper
Browse files Browse the repository at this point in the history
Rename throwhelper methods
  • Loading branch information
cuteant authored Sep 18, 2020
2 parents 88e5e8e + d63bb97 commit e920d1d
Show file tree
Hide file tree
Showing 50 changed files with 185 additions and 130 deletions.
4 changes: 2 additions & 2 deletions src/DotNetty.Buffers/CompositeByteBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ int ToComponentIndex0(int offset)
}
}

return ThrowHelper.ThrowException_ShouldNotReachHere<int>();
return ThrowHelper.FromException_ShouldNotReachHere<int>();
}

public virtual int ToByteIndex(int cIndex)
Expand Down Expand Up @@ -1599,7 +1599,7 @@ ComponentEntry FindIt(int offset)
}
}

return ThrowHelper.ThrowException_ShouldNotReachHere<ComponentEntry>();
return ThrowHelper.FromException_ShouldNotReachHere<ComponentEntry>();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Buffers/Internal/ThrowHelper.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ partial class ThrowHelper
#region -- Exception --

[MethodImpl(MethodImplOptions.NoInlining)]
internal static T ThrowException_ShouldNotReachHere<T>()
internal static T FromException_ShouldNotReachHere<T>()
{
throw GetException();

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Cookies/DefaultCookie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public int CompareTo(object obj)
return CompareTo(cookie);

default:
return ThrowHelper.ThrowArgumentException_CompareToCookie();
return ThrowHelper.FromArgumentException_CompareToCookie();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Cors/CorsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static object GetValue(ICallable<object> callable)
}
catch (Exception exception)
{
return ThrowHelper.ThrowInvalidOperationException_Cqrs(callable, exception);
return ThrowHelper.FromInvalidOperationException_Cqrs(callable, exception);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/HttpObjectAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected override IFullHttpMessage BeginAggregation(IHttpMessage start, IByteBu
case IHttpResponse response:
return new AggregatedFullHttpResponse(response, content, null);
default:
return ThrowHelper.ThrowCodecException_InvalidType(start);
return ThrowHelper.FromCodecException_InvalidType(start);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/DotNetty.Codecs.Http/HttpResponseStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static HttpResponseStatus ParseLine(string line)
}
catch (Exception e)
{
return ThrowHelper.ThrowArgumentException_ParseLine(line, e);
return ThrowHelper.FromArgumentException_ParseLine(line, e);
}
}

Expand All @@ -353,7 +353,7 @@ public static HttpResponseStatus ParseLine(AsciiString line)
}
catch (Exception e)
{
return ThrowHelper.ThrowArgumentException_ParseLine(line, e);
return ThrowHelper.FromArgumentException_ParseLine(line, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/HttpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static long GetContentLength(IHttpMessage message)
}

// Otherwise we don't.
return ThrowHelper.ThrowFormatException_HeaderNotFound();
return ThrowHelper.FromFormatException_HeaderNotFound();
}

public static long GetContentLength(IHttpMessage message, long defaultValue)
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/HttpVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public int CompareTo(object obj)
return this.CompareTo(httpVersion);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpVersion();
return ThrowHelper.FromArgumentException_CompareToHttpVersion();
}

internal void Encode(IByteBuffer buf)
Expand Down
32 changes: 16 additions & 16 deletions src/DotNetty.Codecs.Http/Internal/ThrowHelper.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ ArgumentException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static int ThrowArgumentException_CompareToCookie()
internal static int FromArgumentException_CompareToCookie()
{
throw GetException();

Expand All @@ -553,7 +553,7 @@ static ArgumentException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static int ThrowArgumentException_CompareToHttpVersion()
internal static int FromArgumentException_CompareToHttpVersion()
{
throw GetException();

Expand All @@ -564,7 +564,7 @@ static ArgumentException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static int ThrowArgumentException_CompareToHttpData(HttpDataType x, HttpDataType y)
internal static int FromArgumentException_CompareToHttpData(HttpDataType x, HttpDataType y)
{
throw GetException();
ArgumentException GetException()
Expand Down Expand Up @@ -700,7 +700,7 @@ ArgumentException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static HttpResponseStatus ThrowArgumentException_ParseLine<T>(T line, Exception e)
internal static HttpResponseStatus FromArgumentException_ParseLine<T>(T line, Exception e)
{
throw GetException();
ArgumentException GetException()
Expand Down Expand Up @@ -837,7 +837,7 @@ internal static void ThrowInvalidOperationException_HttpRequestEncoder()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static Task ThrowInvalidOperationException_HttpResponseDecoder()
internal static Task FromInvalidOperationException_HttpResponseDecoder()
{
return TaskUtil.FromException(GetInvalidOperationException<HttpResponseDecoder>());
}
Expand All @@ -848,7 +848,7 @@ internal static InvalidOperationException GetInvalidOperationException<T>()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static Task ThrowInvalidOperationException_NoHttpDecoderAndServerCodec()
internal static Task FromInvalidOperationException_NoHttpDecoderAndServerCodec()
{
return TaskUtil.FromException(GetInvalidOperationException_NoHttpDecoderAndServerCodec());
}
Expand All @@ -865,7 +865,7 @@ internal static InvalidOperationException GetInvalidOperationException_Attemptin
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static object ThrowInvalidOperationException_Cqrs(object callable, Exception exception)
internal static object FromInvalidOperationException_Cqrs(object callable, Exception exception)
{
throw GetException();
InvalidOperationException GetException()
Expand Down Expand Up @@ -1037,7 +1037,7 @@ ChannelException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static T ThrowChannelException_IO<T>(IOException e)
internal static T FromChannelException_IO<T>(IOException e)
{
throw GetException();
ChannelException GetException()
Expand Down Expand Up @@ -1065,7 +1065,7 @@ EncoderException GetException()
#region -- FormatException --

[MethodImpl(MethodImplOptions.NoInlining)]
internal static long ThrowFormatException_HeaderNotFound()
internal static long FromFormatException_HeaderNotFound()
{
throw GetException();

Expand Down Expand Up @@ -1136,7 +1136,7 @@ static NotEnoughDataDecoderException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static StringCharSequence ThrowNotEnoughDataDecoderException_ReadLineStandard()
internal static StringCharSequence FromNotEnoughDataDecoderException_ReadLineStandard()
{
throw GetException();

Expand All @@ -1147,7 +1147,7 @@ static NotEnoughDataDecoderException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static StringCharSequence ThrowNotEnoughDataDecoderException_ReadLine()
internal static StringCharSequence FromNotEnoughDataDecoderException_ReadLine()
{
throw GetException();

Expand All @@ -1158,7 +1158,7 @@ static NotEnoughDataDecoderException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static StringBuilderCharSequence ThrowNotEnoughDataDecoderException_ReadDelimiterStandard()
internal static StringBuilderCharSequence FromNotEnoughDataDecoderException_ReadDelimiterStandard()
{
throw GetException();

Expand All @@ -1169,7 +1169,7 @@ static NotEnoughDataDecoderException GetException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static StringBuilderCharSequence ThrowNotEnoughDataDecoderException_ReadDelimiter()
internal static StringBuilderCharSequence FromNotEnoughDataDecoderException_ReadDelimiter()
{
throw GetException();

Expand Down Expand Up @@ -1304,7 +1304,7 @@ static ErrorDataDecoderException GetErrorDataDecoderException()
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static string ThrowErrorDataDecoderException_BadString(string s, Exception e)
internal static string FromErrorDataDecoderException_BadString(string s, Exception e)
{
throw GetErrorDataDecoderException();
ErrorDataDecoderException GetErrorDataDecoderException()
Expand Down Expand Up @@ -1386,7 +1386,7 @@ static ErrorDataEncoderException GetErrorDataEncoderException()
#region -- CodecException --

[MethodImpl(MethodImplOptions.NoInlining)]
internal static IFullHttpMessage ThrowCodecException_InvalidType(IHttpMessage start)
internal static IFullHttpMessage FromCodecException_InvalidType(IHttpMessage start)
{
throw GetException();
CodecException GetException()
Expand Down Expand Up @@ -1508,7 +1508,7 @@ internal static WebSocketHandshakeException GetWebSocketHandshakeException_SendC
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static WebSocketClientHandshaker ThrowWebSocketHandshakeException_InvalidVersion(WebSocketVersion version)
internal static WebSocketClientHandshaker FromWebSocketHandshakeException_InvalidVersion(WebSocketVersion version)
{
throw GetException();
WebSocketHandshakeException GetException()
Expand Down
14 changes: 14 additions & 0 deletions src/DotNetty.Codecs.Http/Internal/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
using System;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Threading.Tasks;
using DotNetty.Codecs.Http.Internal;
using DotNetty.Common.Utilities;

namespace DotNetty.Codecs.Http
{
Expand Down Expand Up @@ -134,6 +136,18 @@ internal static ArgumentOutOfRangeException GetArgumentOutOfRangeException(Excep

#region -- Throw ArgumentNullException --

[MethodImpl(MethodImplOptions.NoInlining)]
internal static Task FromArgumentNullException(ExceptionArgument argument)
{
return TaskUtil.FromException(GetArgumentNullException(argument));
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static Task<T> FromArgumentNullException<T>(ExceptionArgument argument)
{
return TaskUtil.FromException<T>(GetArgumentNullException(argument));
}

[MethodImpl(MethodImplOptions.NoInlining)]
internal static void ThrowArgumentNullException(ExceptionArgument argument)
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/AbstractHttpData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public IByteBuffer Content
}
catch (IOException e)
{
return ThrowHelper.ThrowChannelException_IO<IByteBuffer>(e);
return ThrowHelper.FromChannelException_IO<IByteBuffer>(e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/DiskAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public override int CompareTo(IInterfaceHttpData other)
return CompareTo(attr);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpData(DataType, other.DataType);
return ThrowHelper.FromArgumentException_CompareToHttpData(DataType, other.DataType);
}

public int CompareTo(IAttribute attribute) => string.Compare(Name, attribute.Name, StringComparison.OrdinalIgnoreCase);
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/DiskFileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public override int CompareTo(IInterfaceHttpData other)
return CompareTo(fu);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpData(DataType, other.DataType);
return ThrowHelper.FromArgumentException_CompareToHttpData(DataType, other.DataType);
}

public int CompareTo(IFileUpload other) => FileUploadUtil.CompareTo(this, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ static StringCharSequence ReadLineStandard(IByteBuffer undecodedChunk, Encoding
}
finally { _ = line.Release(); }
_ = undecodedChunk.SetReaderIndex(readerIndex);
return ThrowHelper.ThrowNotEnoughDataDecoderException_ReadLineStandard();
return ThrowHelper.FromNotEnoughDataDecoderException_ReadLineStandard();
}

static StringCharSequence ReadLine(IByteBuffer undecodedChunk, Encoding charset)
Expand Down Expand Up @@ -1095,7 +1095,7 @@ static StringCharSequence ReadLine(IByteBuffer undecodedChunk, Encoding charset)
_ = line.Release();
}
_ = undecodedChunk.SetReaderIndex(readerIndex);
return ThrowHelper.ThrowNotEnoughDataDecoderException_ReadLine();
return ThrowHelper.FromNotEnoughDataDecoderException_ReadLine();
}

static StringBuilderCharSequence ReadDelimiterStandard(IByteBuffer undecodedChunk, ICharSequence delimiter)
Expand Down Expand Up @@ -1203,7 +1203,7 @@ static StringBuilderCharSequence ReadDelimiterStandard(IByteBuffer undecodedChun
ThrowHelper.ThrowNotEnoughDataDecoderException(e);
}
_ = undecodedChunk.SetReaderIndex(readerIndex);
return ThrowHelper.ThrowNotEnoughDataDecoderException_ReadDelimiterStandard();
return ThrowHelper.FromNotEnoughDataDecoderException_ReadDelimiterStandard();
}

static StringBuilderCharSequence ReadDelimiter(IByteBuffer undecodedChunk, ICharSequence delimiter)
Expand Down Expand Up @@ -1349,7 +1349,7 @@ static StringBuilderCharSequence ReadDelimiter(IByteBuffer undecodedChunk, IChar
ThrowHelper.ThrowNotEnoughDataDecoderException(e);
}
_ = undecodedChunk.SetReaderIndex(readerIndex);
return ThrowHelper.ThrowNotEnoughDataDecoderException_ReadDelimiter();
return ThrowHelper.FromNotEnoughDataDecoderException_ReadDelimiter();
}

static bool LoadDataMultipartStandard(IByteBuffer undecodedChunk, ICharSequence delimiter, IHttpData httpData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ static string DecodeAttribute(string s, Encoding charset)
}
catch (ArgumentException e)
{
return ThrowHelper.ThrowErrorDataDecoderException_BadString(s, e);
return ThrowHelper.FromErrorDataDecoderException_BadString(s, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/InternalAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public int CompareTo(IInterfaceHttpData other)
return this.CompareTo(attr);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpData(this.DataType, other.DataType);
return ThrowHelper.FromArgumentException_CompareToHttpData(this.DataType, other.DataType);
}

public int CompareTo(InternalAttribute other) => string.Compare(this.Name, other.Name, StringComparison.OrdinalIgnoreCase);
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/MemoryAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override int CompareTo(IInterfaceHttpData other)
return this.CompareTo(attr);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpData(this.DataType, other.DataType);
return ThrowHelper.FromArgumentException_CompareToHttpData(this.DataType, other.DataType);
}

public int CompareTo(IAttribute attribute) => string.Compare(this.Name, attribute.Name, StringComparison.OrdinalIgnoreCase);
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetty.Codecs.Http/Multipart/MemoryFileUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override int CompareTo(IInterfaceHttpData other)
return this.CompareTo(fu);
}

return ThrowHelper.ThrowArgumentException_CompareToHttpData(this.DataType, other.DataType);
return ThrowHelper.FromArgumentException_CompareToHttpData(this.DataType, other.DataType);
}

public int CompareTo(IFileUpload other) => FileUploadUtil.CompareTo(this, other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Task HandshakeAsync(IChannel channel)
var codec = pipeline.Get<HttpClientCodec>();
if (codec is null)
{
return ThrowHelper.ThrowInvalidOperationException_HttpResponseDecoder();
return ThrowHelper.FromInvalidOperationException_HttpResponseDecoder();
}
}

Expand Down Expand Up @@ -456,7 +456,7 @@ public override void ChannelInactive(IChannelHandlerContext ctx)
/// <returns></returns>
public Task CloseAsync(IChannel channel, CloseWebSocketFrame frame)
{
if (channel is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.channel); }
if (channel is null) { return ThrowHelper.FromArgumentNullException(ExceptionArgument.channel); }
var completionSource = channel.NewPromise();
_ = channel.WriteAndFlushAsync(frame, completionSource);
ApplyForceCloseTimeout(channel, completionSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static WebSocketClientHandshaker NewHandshaker(
maxFramePayloadLength, forceCloseTimeoutMillis);
}

return ThrowHelper.ThrowWebSocketHandshakeException_InvalidVersion(version);
return ThrowHelper.FromWebSocketHandshakeException_InvalidVersion(version);
}

/// <summary>Creates a new handshaker.</summary>
Expand Down Expand Up @@ -174,7 +174,7 @@ public static WebSocketClientHandshaker NewHandshaker(
maxFramePayloadLength, forceCloseTimeoutMillis, absoluteUpgradeUrl);
}

return ThrowHelper.ThrowWebSocketHandshakeException_InvalidVersion(version);
return ThrowHelper.FromWebSocketHandshakeException_InvalidVersion(version);
}
}
}
Loading

0 comments on commit e920d1d

Please sign in to comment.