From e05f5b37a68e2633769e08bcc3a006bc7862cbd6 Mon Sep 17 00:00:00 2001 From: Krzysztof Bogacki Date: Tue, 20 Jun 2023 12:07:35 +0200 Subject: [PATCH 1/3] Generate better exception messages --- src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs | 2 +- src/LeanCode.ContractsGenerator/IAnalyzer.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs b/src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs index cf05834..6e11b55 100644 --- a/src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs +++ b/src/LeanCode.ContractsGenerator/AnalyzeFailedException.cs @@ -5,7 +5,7 @@ public class AnalyzeFailedException : Exception public IReadOnlyList Errors { get; } public AnalyzeFailedException(IReadOnlyList errors) - : base("Analyze phase failed.") + : base(string.Join('\n', errors.Select(e => e.ToString()).Prepend("Analyze phase failed."))) { Errors = errors; } diff --git a/src/LeanCode.ContractsGenerator/IAnalyzer.cs b/src/LeanCode.ContractsGenerator/IAnalyzer.cs index c086b7a..6de2a9c 100644 --- a/src/LeanCode.ContractsGenerator/IAnalyzer.cs +++ b/src/LeanCode.ContractsGenerator/IAnalyzer.cs @@ -5,4 +5,7 @@ public interface IAnalyzer IEnumerable Analyze(Export export); } -public record AnalyzeError(string Code, string Message, AnalyzerContext Context); +public record AnalyzeError(string Code, string Message, AnalyzerContext Context) +{ + public override string ToString() => $"{Code}: {Message}\n at {Context.Path}"; +} From ae2b32e9056d765bf1cf036330e6fbdce02ea62b Mon Sep 17 00:00:00 2001 From: Krzysztof Bogacki Date: Tue, 20 Jun 2023 13:59:51 +0200 Subject: [PATCH 2/3] Fix AllAnalyzers not being thread-safe --- src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs b/src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs index 406a9d5..ea0e0ac 100644 --- a/src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs +++ b/src/LeanCode.ContractsGenerator/Analyzers/AllAnalyzers.cs @@ -2,7 +2,7 @@ namespace LeanCode.ContractsGenerator.Analyzers; public class AllAnalyzers : IAnalyzer { - private static readonly IReadOnlyList Analyzers = new IAnalyzer[] + private readonly IReadOnlyList analyzers = new IAnalyzer[] { new InternalStructureCheck(), new KnownTypeCheck(), @@ -13,6 +13,6 @@ public class AllAnalyzers : IAnalyzer public IEnumerable Analyze(Export export) { - return Analyzers.SelectMany(a => a.Analyze(export)); + return analyzers.SelectMany(a => a.Analyze(export)); } } From 057bd0e4b6c8188fbb53bcc8791df8942b263b95 Mon Sep 17 00:00:00 2001 From: Krzysztof Bogacki Date: Tue, 20 Jun 2023 14:02:44 +0200 Subject: [PATCH 3/3] Fix stray nullable warning --- .../Compilation/ProjectLoader.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LeanCode.ContractsGenerator/Compilation/ProjectLoader.cs b/src/LeanCode.ContractsGenerator/Compilation/ProjectLoader.cs index 129890c..4e3b15c 100644 --- a/src/LeanCode.ContractsGenerator/Compilation/ProjectLoader.cs +++ b/src/LeanCode.ContractsGenerator/Compilation/ProjectLoader.cs @@ -30,8 +30,10 @@ await Console.Error.WriteLineAsync( foreach (var projectPath in projectPathsList) { if (msbuildWorkspace.CurrentSolution.Projects - .Where(p => p.FilePath is not null) - .Any(p => ResolveCanonicalPath(p.FilePath) == projectPath)) + .Select(p => p.FilePath) + .OfType() + .Select(ResolveCanonicalPath) + .Contains(projectPath)) { continue; }