in src/library/Utilities/AutofacUtilities.cs [93:167]
private static void _Handle<T>(Exception e, ILog log, IOperationContext operationContext, bool isRecurse = false)
{
if (e is IUserVisibleExceptionReporter)
{
log.ExceptionAsWarning(e);
ExceptionDispatchInfo.Capture(e).Throw();
}
else if (e is ArgumentException)
{
log.Exception(e);
ExceptionDispatchInfo.Capture(e).Throw();
}
else if (e is OperationCanceledException)
{
log.ExceptionAsWarning(e);
ExceptionDispatchInfo.Capture(e).Throw();
}
else if (e is DependencyResolutionException && e.InnerException is IUserVisibleExceptionReporter)
{
log.ExceptionAsWarning(e);
ExceptionDispatchInfo.Capture(e.InnerException).Throw();
}
else if (e is DependencyResolutionException)
{
if (e.InnerException is AggregateException)
{
// Try to recurse
_Handle<T>(e.InnerException, log, operationContext, isRecurse: true);
}
// If we get here, we couldn't unwrap to a more specific exception
try
{
log.Exception(e);
log.Flush(TimeSpan.FromMilliseconds(1500));
}
catch { }
throw new ManagementFactoryException(typeof(T), e, operationContext);
}
else if (e is OperationIdException)
{
// This exception has already been logged in the exception strategy class.
ExceptionDispatchInfo.Capture(e).Throw();
}
else
{
if (e is AggregateException agg)
{
log.Verbose($"Attempting to translate AggregateException with {agg.InnerExceptions.Count} exceptions");
log.ExceptionAsWarning(agg);
for (int i = 0; i < agg.InnerExceptions.Count; i++)
{
var ex = agg.InnerExceptions[i];
log.Verbose($"{i + 1}/{agg.InnerExceptions.Count}: {ex.GetType().Name}");
// Recurse
_Handle<T>(ex, log, operationContext, isRecurse: true);
}
}
if (!isRecurse)
{
// If we get here, this is the root of any possible recursion tree and we were unable to unwrap to a more specific exception.
// Log and throw OperationIdException.
try
{
log.Exception(e);
log.Flush(TimeSpan.FromMilliseconds(1500));
}
catch { }
throw new OperationIdException(operationContext, e, e.Message);
}
}
}