Permalink
Browse files

Use error message from inner exception when getting a TargetInvocatio…

…nException
  • Loading branch information...
1 parent 9345438 commit 4aa2eb8f4989ccdb403988ba49f1f1d961c36597 @davidebbo davidebbo committed Nov 9, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 Kudu.Core/Deployment/DeploymentManager.cs
@@ -447,6 +447,14 @@ private void Build(string id, ITracer tracer, IDisposable deployStep)
}
catch (Exception ex)
{
+ // If we get a TargetInvocationException, use the inner exception instead to avoid
+ // useless 'Exception has been thrown by the target of an invocation' messages
+ var targetInvocationException = ex as System.Reflection.TargetInvocationException;
+ if (targetInvocationException != null)
+ {
+ ex = targetInvocationException.InnerException;
+ }
+
_globalLogger.Log(ex);
@amitapl

amitapl Nov 10, 2012

Member

Maybe we should generalize this in the tracer/logger, this may occur in other places and maybe a TargetInvocationException has another TargetInvocationException in it.

@davidfowl

davidfowl Nov 10, 2012

Member

We should do it in both places.

@davidebbo

davidebbo Nov 10, 2012

Owner

Yes, potentially. The one downside is that we lose the Kudu (lower) part of the stack. Though we could fix that as well by walking the exception chain to give all the stacks (like is ASP.NET YSOD).

@davidebbo

davidebbo Nov 10, 2012

Owner

That code suffers from the same stack losing bug though.

tracer.TraceError(ex);

0 comments on commit 4aa2eb8

Please sign in to comment.