Skip to content

Commit

Permalink
Improve error handling of analyzer when producing
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar committed Apr 8, 2024
1 parent 1858bbc commit a52abef
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,38 +284,54 @@ public int Compare(INamedTypeSymbol x, INamedTypeSymbol y)

public CompilationModel ToModel()
{
var comparer = new InheritanceComparer();
var model = new CompilationModel(
_requestMessages
.OrderBy(m => m.Symbol, comparer)
.Select(x => new RequestMessageModel(
x.Symbol,
x.ResponseSymbol,
x.MessageType,
x.Handler?.ToModel(),
x.WrapperType
))
.ToImmutableEquatableArray(),
_notificationMessages.OrderBy(m => m.Symbol, comparer).Select(x => x.ToModel()).ToImmutableEquatableArray(),
_requestMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(),
_notificationMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(),
RequestMessageHandlerWrappers.ToImmutableEquatableArray(),
new NotificationPublisherTypeModel(
_notificationPublisherImplementationSymbol!.GetTypeSymbolFullName(),
_notificationPublisherImplementationSymbol!.Name
),
HasErrors,
MediatorNamespace,
GeneratorVersion,
ServiceLifetime,
ServiceLifetimeShort,
SingletonServiceLifetime,
IsTestRun,
ConfiguredViaAttribute,
ConfiguredViaConfiguration
);
if (HasErrors)
return new CompilationModel(MediatorNamespace, GeneratorVersion);

return model;
try
{
var comparer = new InheritanceComparer();
var model = new CompilationModel(
_requestMessages
.OrderBy(m => m.Symbol, comparer)
.Select(x => new RequestMessageModel(
x.Symbol,
x.ResponseSymbol,
x.MessageType,
x.Handler?.ToModel(),
x.WrapperType
))
.ToImmutableEquatableArray(),
_notificationMessages
.OrderBy(m => m.Symbol, comparer)
.Select(x => x.ToModel())
.ToImmutableEquatableArray(),
_requestMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(),
_notificationMessageHandlers.Select(x => x.ToModel()).ToImmutableEquatableArray(),
RequestMessageHandlerWrappers.ToImmutableEquatableArray(),
new NotificationPublisherTypeModel(
_notificationPublisherImplementationSymbol!.GetTypeSymbolFullName(),
_notificationPublisherImplementationSymbol!.Name
),
HasErrors,
MediatorNamespace,
GeneratorVersion,
ServiceLifetime,
ServiceLifetimeShort,
SingletonServiceLifetime,
IsTestRun,
ConfiguredViaAttribute,
ConfiguredViaConfiguration
);

return model;
}
catch (Exception ex)
{
_context.ReportGenericError(ex);
HasErrors = true;

return new CompilationModel(MediatorNamespace, GeneratorVersion);
}
}

private void FindGlobalNamespaces(Queue<INamespaceOrTypeSymbol> queue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ internal record CompilationModel
private readonly ImmutableEquatableArray<RequestMessageHandlerModel> _requestMessageHandlers;
private readonly ImmutableEquatableArray<NotificationMessageHandlerModel> _notificationMessageHandlers;

public CompilationModel(string mediatorNamespace, string generatorVersion)
{
HasErrors = true;
MediatorNamespace = mediatorNamespace;
GeneratorVersion = generatorVersion;
_requestMessages = ImmutableEquatableArray<RequestMessageModel>.Empty;
_notificationMessages = ImmutableEquatableArray<NotificationMessageModel>.Empty;
_requestMessageHandlers = ImmutableEquatableArray<RequestMessageHandlerModel>.Empty;
_notificationMessageHandlers = ImmutableEquatableArray<NotificationMessageHandlerModel>.Empty;
RequestMessageHandlerWrappers = ImmutableEquatableArray<RequestMessageHandlerWrapperModel>.Empty;
}

public CompilationModel(
ImmutableEquatableArray<RequestMessageModel> requestMessages,
ImmutableEquatableArray<NotificationMessageModel> notificationMessages,
Expand Down

0 comments on commit a52abef

Please sign in to comment.