diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2019-03-26 11:33:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-26 11:33:48 +0300 |
commit | 762cc8e5557c7cd4ba91558112378f5cfc40724d (patch) | |
tree | 143c9599680d5c78ac3bbe9cb71c20d4779edf30 | |
parent | 57b28182cb714c46226645b47fa80cb3d23f1f79 (diff) | |
parent | 81b9e75a29fdf8bf2d9352c20c81e46416ffb21d (diff) |
Merge pull request #3695 from warwickmm/unwrap_reflection_exceptions
Unwrap TargetInvocationExceptions while preserving stack trace
-rw-r--r-- | Duplicati/Library/AutoUpdater/UpdaterManager.cs | 19 | ||||
-rw-r--r-- | Duplicati/Library/DynamicLoader/BackendLoader.cs | 8 |
2 files changed, 18 insertions, 9 deletions
diff --git a/Duplicati/Library/AutoUpdater/UpdaterManager.cs b/Duplicati/Library/AutoUpdater/UpdaterManager.cs index 89e4b596d..813056294 100644 --- a/Duplicati/Library/AutoUpdater/UpdaterManager.cs +++ b/Duplicati/Library/AutoUpdater/UpdaterManager.cs @@ -18,12 +18,13 @@ using System;
using System.Linq;
using System.Collections.Generic;
-using System.IO; +using System.IO;
+using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Duplicati.Library.Interface;
-using Duplicati.Library.Common.IO; -using Duplicati.Library.Common; - +using Duplicati.Library.Common.IO;
+using Duplicati.Library.Common;
+
namespace Duplicati.Library.AutoUpdater
{
public enum AutoUpdateStrategy
@@ -1025,9 +1026,13 @@ namespace Duplicati.Library.AutoUpdater }
if (tex.InnerException != null)
- throw tex.InnerException;
- else
- throw;
+ {
+ // Unwrap exceptions for nicer display. The ExceptionDispatchInfo class allows us to
+ // rethrow an exception without changing the stack trace.
+ ExceptionDispatchInfo.Capture(tex.InnerException).Throw();
+ }
+
+ throw;
}
}
diff --git a/Duplicati/Library/DynamicLoader/BackendLoader.cs b/Duplicati/Library/DynamicLoader/BackendLoader.cs index 88ed5e0e6..e563d6f78 100644 --- a/Duplicati/Library/DynamicLoader/BackendLoader.cs +++ b/Duplicati/Library/DynamicLoader/BackendLoader.cs @@ -24,6 +24,7 @@ using Duplicati.Library.Interface; using System.Collections.Specialized;
using System.Web;
using System.Linq;
+using System.Runtime.ExceptionServices;
namespace Duplicati.Library.DynamicLoader
{
@@ -96,9 +97,12 @@ namespace Duplicati.Library.DynamicLoader }
catch (System.Reflection.TargetInvocationException tex)
{
- // Unwrap exceptions for nicer display
if (tex.InnerException != null)
- throw new Exception("Unwrapped TargetInvocationException", tex.InnerException);
+ {
+ // Unwrap exceptions for nicer display. The ExceptionDispatchInfo class allows us to
+ // rethrow an exception without changing the stack trace.
+ ExceptionDispatchInfo.Capture(tex.InnerException).Throw();
+ }
throw;
}
|