THRIFT-4609 keep InnerException wherever appropriate

Client: C#
Patch: Jens Geyer

This closes #1576
This commit is contained in:
Jens Geyer 2018-08-06 23:31:38 +02:00
parent 831819c563
commit 6e67faa928
9 changed files with 38 additions and 37 deletions

View File

@ -859,19 +859,21 @@ namespace Thrift.Protocol
{ {
ReadJSONSyntaxChar(QUOTE); ReadJSONSyntaxChar(QUOTE);
} }
string str = ReadJSONNumericChars(); string str = ReadJSONNumericChars();
if (context.EscapeNumbers()) if (context.EscapeNumbers())
{ {
ReadJSONSyntaxChar(QUOTE); ReadJSONSyntaxChar(QUOTE);
} }
try try
{ {
return Int64.Parse(str); return Int64.Parse(str);
} }
catch (FormatException) catch (FormatException fex)
{ {
throw new TProtocolException(TProtocolException.INVALID_DATA, throw new TProtocolException(TProtocolException.INVALID_DATA,
"Bad data encounted in numeric data"); "Bad data encounted in numeric data", fex);
} }
} }
@ -887,8 +889,7 @@ namespace Thrift.Protocol
byte[] arr = ReadJSONString(true); byte[] arr = ReadJSONString(true);
double dub = Double.Parse(utf8Encoding.GetString(arr, 0, arr.Length), CultureInfo.InvariantCulture); double dub = Double.Parse(utf8Encoding.GetString(arr, 0, arr.Length), CultureInfo.InvariantCulture);
if (!context.EscapeNumbers() && !Double.IsNaN(dub) && if (!context.EscapeNumbers() && !Double.IsNaN(dub) && !Double.IsInfinity(dub))
!Double.IsInfinity(dub))
{ {
// Throw exception -- we should not be in a string in this case // Throw exception -- we should not be in a string in this case
throw new TProtocolException(TProtocolException.INVALID_DATA, throw new TProtocolException(TProtocolException.INVALID_DATA,
@ -907,10 +908,10 @@ namespace Thrift.Protocol
{ {
return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture); return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture);
} }
catch (FormatException) catch (FormatException fex)
{ {
throw new TProtocolException(TProtocolException.INVALID_DATA, throw new TProtocolException(TProtocolException.INVALID_DATA,
"Bad data encounted in numeric data"); "Bad data encounted in numeric data", fex);
} }
} }
} }

View File

@ -48,14 +48,14 @@ namespace Thrift.Protocol
type_ = type; type_ = type;
} }
public TProtocolException(int type, string message) public TProtocolException(int type, string message, Exception inner = null)
: base(message) : base(message, inner)
{ {
type_ = type; type_ = type;
} }
public TProtocolException(string message) public TProtocolException(string message, Exception inner = null)
: base(message) : base(message, inner)
{ {
} }

View File

@ -40,7 +40,7 @@ namespace Thrift
} }
public TApplicationException(ExceptionType type, string message) public TApplicationException(ExceptionType type, string message)
: base(message) : base(message, null) // TApplicationException is serializable, but we never serialize InnerException
{ {
this.type = type; this.type = type;
} }

View File

@ -31,8 +31,8 @@ namespace Thrift
{ {
} }
public TException(string message) public TException(string message, Exception inner)
: base(message) : base(message, inner)
{ {
} }

View File

@ -139,7 +139,7 @@ namespace Thrift.Transport
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString()); throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
} }
} }
@ -217,11 +217,11 @@ namespace Thrift.Transport
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString()); throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
} }
catch (WebException wx) 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);
} }
} }
@ -316,7 +316,7 @@ namespace Thrift.Transport
} }
catch (IOException iox) catch (IOException iox)
{ {
throw new TTransportException(iox.ToString()); throw new TTransportException(iox.ToString(), iox);
} }
} }
@ -360,7 +360,7 @@ namespace Thrift.Transport
} }
catch (Exception exception) catch (Exception exception)
{ {
flushAsyncResult.AsyncException = new TTransportException(exception.ToString()); flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
flushAsyncResult.UpdateStatusToComplete(); flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable(); flushAsyncResult.NotifyCallbackWhenAvailable();
} }
@ -375,7 +375,7 @@ namespace Thrift.Transport
} }
catch (Exception exception) catch (Exception exception)
{ {
flushAsyncResult.AsyncException = new TTransportException(exception.ToString()); flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
} }
flushAsyncResult.UpdateStatusToComplete(); flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable(); flushAsyncResult.NotifyCallbackWhenAvailable();

View File

@ -130,7 +130,7 @@ namespace Thrift.Transport
if (stream != null) if (stream != null)
eOuter = e; eOuter = e;
else else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message); eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
} }
evt.Set(); evt.Set();
}, null); }, null);
@ -157,7 +157,7 @@ namespace Thrift.Transport
catch (Exception e) catch (Exception e)
{ {
Close(); Close();
throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message); throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message, e);
} }
} }
@ -214,7 +214,7 @@ namespace Thrift.Transport
if (stream != null) if (stream != null)
eOuter = e; eOuter = e;
else else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message); eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
} }
evt.Set(); evt.Set();
}, null); }, null);
@ -265,7 +265,7 @@ namespace Thrift.Transport
if (stream != null) if (stream != null)
eOuter = e; eOuter = e;
else else
eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message); eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
} }
evt.Set(); evt.Set();
}, null); }, null);

View File

@ -93,10 +93,10 @@ namespace Thrift.Transport
this.server = TSocketVersionizer.CreateTcpListener(this.port); this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true; this.server.Server.NoDelay = true;
} }
catch (Exception) catch (Exception ex)
{ {
server = null; 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);
} }
} }
@ -111,7 +111,7 @@ namespace Thrift.Transport
} }
catch (SocketException sx) 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);
} }
} }
} }
@ -153,7 +153,7 @@ namespace Thrift.Transport
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new TTransportException(ex.ToString()); throw new TTransportException(ex.ToString(), ex);
} }
} }
@ -167,7 +167,7 @@ namespace Thrift.Transport
} }
catch (Exception ex) 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; server = null;
} }

View File

@ -129,10 +129,10 @@ namespace Thrift.Transport
this.server = TSocketVersionizer.CreateTcpListener(this.port); this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true; this.server.Server.NoDelay = true;
} }
catch (Exception) catch (Exception ex)
{ {
server = null; 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);
} }
} }
@ -150,7 +150,7 @@ namespace Thrift.Transport
} }
catch (SocketException sx) 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);
} }
} }
} }
@ -197,7 +197,7 @@ namespace Thrift.Transport
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new TTransportException(ex.ToString()); throw new TTransportException(ex.ToString(), ex);
} }
} }
@ -214,7 +214,7 @@ namespace Thrift.Transport
} }
catch (Exception ex) 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; this.server = null;
} }

View File

@ -40,14 +40,14 @@ namespace Thrift.Transport
this.type = type; this.type = type;
} }
public TTransportException(ExceptionType type, string message) public TTransportException(ExceptionType type, string message, Exception inner = null)
: base(message) : base(message, inner)
{ {
this.type = type; this.type = type;
} }
public TTransportException(string message) public TTransportException(string message, Exception inner = null)
: base(message) : base(message, inner)
{ {
} }