Skip to content

Commit

Permalink
Make sure generated file has actual code on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
parched committed Dec 5, 2024
1 parent 901ada2 commit 7116076
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/FlatSharp.Compiler/FlatSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private static int RunCompiler(CompilerOptions options)
Exception? exception = null;
try
{
cSharp = CreateCSharp(bfbs, inputHash, options);
CreateCSharp(bfbs, inputHash, options, out cSharp);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -356,7 +356,7 @@ private static (Assembly, string) CompileAndLoadAssemblyWithCode(
options.InputFiles = fbsFiles.Select(x => x.FullName);

List<(byte[], string)> bfbs = GetBfbs(options);
string cSharp = CreateCSharp(bfbs, "hash", options);
CreateCSharp(bfbs, "hash", options, out var cSharp);

var (assembly, formattedText, _) = RoslynSerializerGenerator.CompileAssembly(cSharp, true, additionalRefs);
string debugText = formattedText();
Expand Down Expand Up @@ -526,10 +526,11 @@ private static string GetFlatcPath()
return flatcPath;
}

private static string CreateCSharp(
private static void CreateCSharp(
List<(byte[] bfbs, string inputPath)> bfbs,
string inputHash,
CompilerOptions options)
CompilerOptions options,
out string result)
{
string csharp = string.Empty;

Expand Down Expand Up @@ -621,15 +622,20 @@ private static string CreateCSharp(
return csharp;
});
}
catch (FlatSharpCompilationException e)
{
csharp = e.CSharp;
throw;
}
finally
{
if (csharp is not null)
{
csharp = Instrument("PrettyPrint", options, () => RoslynSerializerGenerator.GetFormattedText(csharp));
}
}

return csharp;
result = csharp;

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022, win-x64)

Possible null reference assignment.

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022, win-x64)

Possible null reference assignment.

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, linux-x64)

Possible null reference assignment.

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, linux-x64)

Possible null reference assignment.

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check failure on line 637 in src/FlatSharp.Compiler/FlatSharpCompiler.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
}
}

private static Schema.Schema ParseSchema(
Expand Down

0 comments on commit 7116076

Please sign in to comment.