Skip to content

Commit

Permalink
Added line content to compilation exception message.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-dunwiddie committed Dec 31, 2024
1 parent a99a5f7 commit 753f27e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Data_Eval/Data_Eval/Compilation/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ public Type Compile(
foreach (var error in emitResult.Diagnostics
.Where(e => e.Severity == DiagnosticSeverity.Error || e.IsWarningAsError)
.OrderBy(e => e.Location.GetLineSpan().StartLinePosition.Line))
{
exceptionMessage += "\n\tLine " + error.Location.GetLineSpan().StartLinePosition.Line.ToString() + ": " + error.GetMessage();
{
exceptionMessage += "\n\tError: " + error.GetMessage();

string code = classText.Replace("\r\n", "\n").Split('\r', '\n')[error.Location.GetLineSpan().StartLinePosition.Line].Trim().TrimEnd(';');

exceptionMessage += "\n\tOn Line " + error.Location.GetLineSpan().StartLinePosition.Line.ToString() + ": " + code;
}

throw new CompilationException(exceptionMessage)
Expand Down
4 changes: 3 additions & 1 deletion Data_Eval/Data_Eval/Data_Eval.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>Data_Eval.snk</AssemblyOriginatorKeyFile>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Description></Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
6 changes: 3 additions & 3 deletions Data_Eval/Data_Eval/Data_Eval.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
<package>
<metadata>
<id>Data.Eval</id>
<version>2.6.0</version>
<version>2.6.1</version>
<title>Data.Eval</title>
<authors>Bruce Dunwiddie</authors>
<owners>shriop</owners>
<license type="expression">Apache-2.0</license>
<projectUrl>https://github.com/bruce-dunwiddie/data-eval</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>.Net Library for Evaluating Expressions at Runtime</description>
<releaseNotes>Cache compilation exceptions to speed up looped exception creation.</releaseNotes>
<copyright>Copyright © 2023</copyright>
<releaseNotes>Added line content to compilation exception message.</releaseNotes>
<copyright>Copyright © 2025</copyright>
<tags>eval expression evaluator compile</tags>
<dependencies>
<dependency id="Microsoft.CodeAnalysis" version="3.6.0" />
Expand Down
2 changes: 1 addition & 1 deletion Data_Eval/Data_Eval/Pack.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nuget pack Data_Eval.nuspec -Symbols -SymbolPackageFormat snupkg
nuget push Data.Eval.2.6.0.nupkg -Source https://api.nuget.org/v3/index.json -apikey %NUGET_KEY%
nuget push Data.Eval.2.6.1.nupkg -Source https://api.nuget.org/v3/index.json -apikey %NUGET_KEY%
pause
2 changes: 1 addition & 1 deletion Data_Eval/Tests/Compilation/CompilerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public object Eval(){
"CustomEvaluator");
});

Assert.AreEqual("Class failed to compile.\n\tLine 6: ; expected", ex.Message);
Assert.AreEqual("Class failed to compile.\n\tError: ; expected\n\tOn Line 6: return intValue + 1", ex.Message);
Assert.AreEqual(codeToCompile, ex.GeneratedClassCode);
}
}
Expand Down

0 comments on commit 753f27e

Please sign in to comment.