[
https://issues.apache.org/jira/browse/THRIFT-4609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16572364#comment-16572364
]
ASF GitHub Bot commented on THRIFT-4609:
----------------------------------------
Jens-G closed pull request #1576: THRIFT-4609 keep InnerException wherever
appropriate
URL: https://github.com/apache/thrift/pull/1576
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/lib/csharp/src/Protocol/TJSONProtocol.cs
b/lib/csharp/src/Protocol/TJSONProtocol.cs
index 3390dc0dd4..9dbdea9aae 100644
--- a/lib/csharp/src/Protocol/TJSONProtocol.cs
+++ b/lib/csharp/src/Protocol/TJSONProtocol.cs
@@ -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);
}
}
@@ -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,
@@ -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);
}
}
}
diff --git a/lib/csharp/src/Protocol/TProtocolException.cs
b/lib/csharp/src/Protocol/TProtocolException.cs
index a89c3fc899..c0f007e0ce 100644
--- a/lib/csharp/src/Protocol/TProtocolException.cs
+++ b/lib/csharp/src/Protocol/TProtocolException.cs
@@ -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)
{
}
diff --git a/lib/csharp/src/TApplicationException.cs
b/lib/csharp/src/TApplicationException.cs
index 0c5b08b577..8dd7ae5782 100644
--- a/lib/csharp/src/TApplicationException.cs
+++ b/lib/csharp/src/TApplicationException.cs
@@ -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;
}
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
index 35193c5c10..aa9a210c97 100644
--- a/lib/csharp/src/TException.cs
+++ b/lib/csharp/src/TException.cs
@@ -31,8 +31,8 @@ public TException()
{
}
- public TException(string message)
- : base(message)
+ public TException(string message, Exception inner)
+ : base(message, inner)
{
}
diff --git a/lib/csharp/src/Transport/THttpClient.cs
b/lib/csharp/src/Transport/THttpClient.cs
index 06ed6bcadc..667fc2526c 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
@@ -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();
diff --git a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
index a6cfb2e787..32215cfc10 100644
--- a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
diff --git a/lib/csharp/src/Transport/TServerSocket.cs
b/lib/csharp/src/Transport/TServerSocket.cs
index 40e47dcf1a..d8ec62ab3f 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -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);
}
}
@@ -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);
}
}
}
@@ -153,7 +153,7 @@ protected override TTransport AcceptImpl()
}
catch (Exception ex)
{
- throw new TTransportException(ex.ToString());
+ throw new TTransportException(ex.ToString(), ex);
}
}
@@ -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;
}
diff --git a/lib/csharp/src/Transport/TTLSServerSocket.cs
b/lib/csharp/src/Transport/TTLSServerSocket.cs
index aa8ff7cbd3..716a97ca84 100644
--- a/lib/csharp/src/Transport/TTLSServerSocket.cs
+++ b/lib/csharp/src/Transport/TTLSServerSocket.cs
@@ -129,10 +129,10 @@ public TTLSServerSocket(int port, int clientTimeout,
X509Certificate2 certificat
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);
}
}
@@ -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);
}
}
}
@@ -197,7 +197,7 @@ protected override TTransport AcceptImpl()
}
catch (Exception ex)
{
- throw new TTransportException(ex.ToString());
+ throw new TTransportException(ex.ToString(), ex);
}
}
@@ -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;
}
diff --git a/lib/csharp/src/Transport/TTransportException.cs
b/lib/csharp/src/Transport/TTransportException.cs
index ae987d5c20..7f6cc1889e 100644
--- a/lib/csharp/src/Transport/TTransportException.cs
+++ b/lib/csharp/src/Transport/TTransportException.cs
@@ -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)
{
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> keep InnerException wherever appropriate
> -----------------------------------------
>
> Key: THRIFT-4609
> URL: https://issues.apache.org/jira/browse/THRIFT-4609
> Project: Thrift
> Issue Type: Improvement
> Components: C# - Library
> Reporter: Jens Geyer
> Assignee: Jens Geyer
> Priority: Major
>
> The C# {{Exception}} type offers the ability to store an {{InnerException}}
> which is sometimes quite helpful for debugging. Hence, wherever appropriate,
> any exceptions caught and rethrown should be stored into the
> {{InnerException}} field to provide the original error information to the
> caller.
> The only exception (pun intended) to this is {{TApplicationException}} - this
> type is intended to be serialized and sent back to the client. Not only that
> there is no way to preserve that information, it also [could compromise
> possibly sensitive information to clients, which is a bad thing to happen
> w/regard to security|https://cwe.mitre.org/data/definitions/209.html].
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)