Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure generated file has actual code on exception #456

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 @@
return csharp;
});
}
catch (FlatSharpCompilationException e)
{
csharp = e.CSharp;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is only really useful when code generation for reading bfbs fails, so should never be hit by an end user, but is useful for flatsharp developers

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Looks like you have a nullability error.

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
Loading