From e93d1fb640315d83eb72d72d18cadd6b4f9a33c3 Mon Sep 17 00:00:00 2001 From: Sajid Date: Sun, 17 Sep 2023 20:12:55 +0600 Subject: [PATCH] Don't use exceptions in CompileCodes --- .../CodeProvider.cs | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/Source/Libraries/HedgeModManager.CodeCompiler/CodeProvider.cs b/Source/Libraries/HedgeModManager.CodeCompiler/CodeProvider.cs index a25901d..04202e4 100644 --- a/Source/Libraries/HedgeModManager.CodeCompiler/CodeProvider.cs +++ b/Source/Libraries/HedgeModManager.CodeCompiler/CodeProvider.cs @@ -66,7 +66,8 @@ public static Task CompileCodes(TCollection sources, Stream }); } - public static Task CompileCodes(in CompilerOptions compileOptions) where TCollection : IEnumerable + public static Task CompileCodes(in CompilerOptions compileOptions) + where TCollection : IEnumerable { var sources = compileOptions.Sources; var includeResolver = compileOptions.IncludeResolver; @@ -74,10 +75,12 @@ public static Task CompileCodes(in CompilerOptions(); var newLibs = new HashSet(); var loads = GetLoadAssemblies(sources, includeResolver, loadPaths); + var resultStream = compileOptions.OutputStream; // We don't have to concern ourselves with resolving references if everything is compiled if (compileOptions.IncludeAllSources) @@ -100,12 +103,12 @@ public static Task CompileCodes(in CompilerOptions CompileCodes(in CompilerOptions(newLibs.Count); - foreach (string lib in newLibs) + var hasError = false; + foreach (string libIter in newLibs) { + var lib = libIter; + var dividerIndex = lib.IndexOf('\x00'); + var sourceRef = string.Empty; + + if (dividerIndex != -1) + { + sourceRef = lib.Substring(0, dividerIndex); + lib = lib.Substring(dividerIndex + 1); + } + if (libs.Contains(lib)) { continue; @@ -124,7 +138,9 @@ public static Task CompileCodes(in CompilerOptions x.Name == lib); if (libSource == null) { - throw new Exception($"Unable to find dependency library {lib}"); + report.Error(sourceRef, $"Unable to find dependency library '{lib}'"); + hasError = true; + continue; } trees.Add(libSource.CreateSyntaxTree(includeResolver)); @@ -141,38 +157,47 @@ public static Task CompileCodes(in CompilerOptions