Skip to content

Commit

Permalink
THRIFT-4609 keep InnerException wherever appropriate
Browse files Browse the repository at this point in the history
Client: C#
Patch: Jens Geyer

This closes apache#1576
  • Loading branch information
Jens-G committed Aug 7, 2018
1 parent 831819c commit 6e67faa
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
13 changes: 7 additions & 6 deletions lib/csharp/src/Protocol/TJSONProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -859,19 +859,21 @@ private long ReadJSONInteger()
{
ReadJSONSyntaxChar(QUOTE);
}

string str = ReadJSONNumericChars();
if (context.EscapeNumbers())
{
ReadJSONSyntaxChar(QUOTE);
}

try
{
return Int64.Parse(str);
}
catch (FormatException)
catch (FormatException fex)
{
throw new TProtocolException(TProtocolException.INVALID_DATA,
"Bad data encounted in numeric data");
"Bad data encounted in numeric data", fex);
}
}

Expand All @@ -887,8 +889,7 @@ private double ReadJSONDouble()
byte[] arr = ReadJSONString(true);
double dub = Double.Parse(utf8Encoding.GetString(arr, 0, arr.Length), CultureInfo.InvariantCulture);

if (!context.EscapeNumbers() && !Double.IsNaN(dub) &&
!Double.IsInfinity(dub))
if (!context.EscapeNumbers() && !Double.IsNaN(dub) && !Double.IsInfinity(dub))
{
// Throw exception -- we should not be in a string in this case
throw new TProtocolException(TProtocolException.INVALID_DATA,
Expand All @@ -907,10 +908,10 @@ private double ReadJSONDouble()
{
return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture);
}
catch (FormatException)
catch (FormatException fex)
{
throw new TProtocolException(TProtocolException.INVALID_DATA,
"Bad data encounted in numeric data");
"Bad data encounted in numeric data", fex);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/csharp/src/Protocol/TProtocolException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public TProtocolException(int type)
type_ = type;
}

public TProtocolException(int type, string message)
: base(message)
public TProtocolException(int type, string message, Exception inner = null)
: base(message, inner)
{
type_ = type;
}

public TProtocolException(string message)
: base(message)
public TProtocolException(string message, Exception inner = null)
: base(message, inner)
{
}

Expand Down
2 changes: 1 addition & 1 deletion lib/csharp/src/TApplicationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TApplicationException(ExceptionType type)
}

public TApplicationException(ExceptionType type, string message)
: base(message)
: base(message, null) // TApplicationException is serializable, but we never serialize InnerException
{
this.type = type;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/csharp/src/TException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public TException()
{
}

public TException(string message)
: base(message)
public TException(string message, Exception inner)
: base(message, inner)
{
}

Expand Down
12 changes: 6 additions & 6 deletions lib/csharp/src/Transport/THttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override int Read(byte[] buf, int off, int len)
}
catch (IOException iox)
{
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
}
}

Expand Down Expand Up @@ -217,11 +217,11 @@ private void SendRequest()
}
catch (IOException iox)
{
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
}
catch (WebException wx)
{
throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx, wx);
}
}

Expand Down Expand Up @@ -316,7 +316,7 @@ public override IAsyncResult BeginFlush(AsyncCallback callback, object state)
}
catch (IOException iox)
{
throw new TTransportException(iox.ToString());
throw new TTransportException(iox.ToString(), iox);
}
}

Expand Down Expand Up @@ -360,7 +360,7 @@ private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
}
catch (Exception exception)
{
flushAsyncResult.AsyncException = new TTransportException(exception.ToString());
flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable();
}
Expand All @@ -375,7 +375,7 @@ private void GetResponseCallback(IAsyncResult asynchronousResult)
}
catch (Exception exception)
{
flushAsyncResult.AsyncException = new TTransportException(exception.ToString());
flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
}
flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable();
Expand Down
8 changes: 4 additions & 4 deletions lib/csharp/src/Transport/TNamedPipeServerTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected override TTransport AcceptImpl()
if (stream != null)
eOuter = e;
else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
Expand All @@ -157,7 +157,7 @@ protected override TTransport AcceptImpl()
catch (Exception e)
{
Close();
throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message, e);
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ public override int Read(byte[] buf, int off, int len)
if (stream != null)
eOuter = e;
else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
Expand Down Expand Up @@ -265,7 +265,7 @@ public override void Write(byte[] buf, int off, int len)
if (stream != null)
eOuter = e;
else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
Expand Down
10 changes: 5 additions & 5 deletions lib/csharp/src/Transport/TServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true;
}
catch (Exception)
catch (Exception ex)
{
server = null;
throw new TTransportException("Could not create ServerSocket on port " + this.port + ".");
throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
}
}

Expand All @@ -111,7 +111,7 @@ public override void Listen()
}
catch (SocketException sx)
{
throw new TTransportException("Could not accept on listening socket: " + sx.Message);
throw new TTransportException("Could not accept on listening socket: " + sx.Message, sx);
}
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ protected override TTransport AcceptImpl()
}
catch (Exception ex)
{
throw new TTransportException(ex.ToString());
throw new TTransportException(ex.ToString(), ex);
}
}

Expand All @@ -167,7 +167,7 @@ public override void Close()
}
catch (Exception ex)
{
throw new TTransportException("WARNING: Could not close server socket: " + ex);
throw new TTransportException("WARNING: Could not close server socket: " + ex, ex);
}
server = null;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/csharp/src/Transport/TTLSServerSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public TTLSServerSocket(
this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true;
}
catch (Exception)
catch (Exception ex)
{
server = null;
throw new TTransportException("Could not create ServerSocket on port " + this.port + ".");
throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
}
}

Expand All @@ -150,7 +150,7 @@ public override void Listen()
}
catch (SocketException sx)
{
throw new TTransportException("Could not accept on listening socket: " + sx.Message);
throw new TTransportException("Could not accept on listening socket: " + sx.Message, sx);
}
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ protected override TTransport AcceptImpl()
}
catch (Exception ex)
{
throw new TTransportException(ex.ToString());
throw new TTransportException(ex.ToString(), ex);
}
}

Expand All @@ -214,7 +214,7 @@ public override void Close()
}
catch (Exception ex)
{
throw new TTransportException("WARNING: Could not close server socket: " + ex);
throw new TTransportException("WARNING: Could not close server socket: " + ex, ex);
}
this.server = null;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/csharp/src/Transport/TTransportException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public TTransportException(ExceptionType type)
this.type = type;
}

public TTransportException(ExceptionType type, string message)
: base(message)
public TTransportException(ExceptionType type, string message, Exception inner = null)
: base(message, inner)
{
this.type = type;
}

public TTransportException(string message)
: base(message)
public TTransportException(string message, Exception inner = null)
: base(message, inner)
{
}

Expand Down

0 comments on commit 6e67faa

Please sign in to comment.