Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass full exception rather than just message for TypeLoadingErrorWarning #33295

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/EFCore/Diagnostics/CoreLoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,17 +722,17 @@ public static void SensitiveDataLoggingEnabledWarning<TLoggerCategory>(
/// </summary>
/// <param name="diagnostics">The diagnostics logger to use.</param>
/// <param name="assembly">The assembly that types are being loaded from.</param>
/// <param name="exceptionMessage">The exception message from the loading error.</param>
/// <param name="exception">The exception from the loading error.</param>
public static void TypeLoadingErrorWarning(
this IDiagnosticsLogger<DbLoggerCategory.Model> diagnostics,
Assembly assembly,
string exceptionMessage)
Exception exception)
{
var definition = CoreResources.LogTypeLoadingErrorWarning(diagnostics);

if (diagnostics.ShouldLog(definition))
{
definition.Log(diagnostics, assembly.ToString(), exceptionMessage);
definition.Log(diagnostics, assembly.ToString(), exception.Message);
}

if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
Expand All @@ -741,7 +741,7 @@ public static void TypeLoadingErrorWarning(
definition,
TypeLoadingErrorWarning,
assembly,
exceptionMessage);
exception);

diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
}
Expand All @@ -751,7 +751,7 @@ private static string TypeLoadingErrorWarning(EventDefinitionBase definition, Ev
{
var d = (EventDefinition<string, string>)definition;
var p = (TypeLoadingEventData)payload;
return d.GenerateMessage(p.Assembly.ToString(), p.ExceptionMessage);
return d.GenerateMessage(p.Assembly.ToString(), p.Exception.Message);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions src/EFCore/Diagnostics/TypeLoadingEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ namespace Microsoft.EntityFrameworkCore.Diagnostics;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-diagnostics">Logging, events, and diagnostics</see> for more information and examples.
/// </remarks>
public class TypeLoadingEventData : AssemblyEventData
public class TypeLoadingEventData : AssemblyEventData, IErrorEventData
{
/// <summary>
/// Constructs the event payload.
/// Initializes a new instance of the <see cref="TypeLoadingEventData"/> class.
/// </summary>
/// <param name="eventDefinition">The event definition.</param>
/// <param name="messageGenerator">A delegate that generates a log message for this event.</param>
/// <param name="assembly">The assembly from which types are being loaded.</param>
/// <param name="exceptionMessage">The exception message.</param>
/// <param name="exception">The exception message.</param>
public TypeLoadingEventData(
EventDefinitionBase eventDefinition,
Func<EventDefinitionBase, EventData, string> messageGenerator,
Assembly assembly,
string exceptionMessage)
Exception exception)
: base(eventDefinition, messageGenerator, assembly)
{
ExceptionMessage = exceptionMessage;
Exception = exception;
}

/// <summary>
/// The exception message.
/// Gets the type-loading exception.
/// </summary>
public virtual string ExceptionMessage { get; }
public virtual Exception Exception { get; }
}
2 changes: 1 addition & 1 deletion src/Shared/SharedTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public static IEnumerable<TypeInfo> GetLoadableDefinedTypes(
}
catch (ReflectionTypeLoadException ex)
{
logger?.TypeLoadingErrorWarning(assembly, ex.Message);
logger?.TypeLoadingErrorWarning(assembly, ex);

return ex.Types.Where(t => t != null).Select(IntrospectionExtensions.GetTypeInfo!);
}
Expand Down
Loading