Skip to content

Commit

Permalink
Do Not Write JSON for Error Files
Browse files Browse the repository at this point in the history
Excludes writing the JSON for files that failed to parse.
  • Loading branch information
DavidBakerEffendi committed Dec 5, 2023
1 parent 059f8c8 commit 3a52388
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions DotNetAstGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,27 @@ private static void _AstForFile(
else
{
_logger?.LogInformation("Successfully parsed: {filePath}", fullPath);
}

var astGenResult = new AstGenWrapper(fullPath, tree);
var jsonString = JsonConvert.SerializeObject(astGenResult, Formatting.Indented,
new JsonSerializerSettings
var astGenResult = new AstGenWrapper(fullPath, tree);
var jsonString = JsonConvert.SerializeObject(astGenResult, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ContractResolver =
new SyntaxNodePropertiesResolver() // Comment this to see the unfiltered parser output
});
var outputName = Path.Combine(filePath.DirectoryName ?? "./",
$"{Path.GetFileNameWithoutExtension(fullPath)}.json")
.Replace(rootInputPath.FullName, rootOutputPath.FullName);

// Create dirs if they do not exist
var outputParentDir = Path.GetDirectoryName(outputName);
if (outputParentDir != null)
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
ContractResolver =
new SyntaxNodePropertiesResolver() // Comment this to see the unfiltered parser output
});
var outputName = Path.Combine(filePath.DirectoryName ?? "./",
$"{Path.GetFileNameWithoutExtension(fullPath)}.json")
.Replace(rootInputPath.FullName, rootOutputPath.FullName);
Directory.CreateDirectory(outputParentDir);
}

// Create dirs if they do not exist
var outputParentDir = Path.GetDirectoryName(outputName);
if (outputParentDir != null)
{
Directory.CreateDirectory(outputParentDir);
File.WriteAllText(outputName, jsonString);
}

File.WriteAllText(outputName, jsonString);
}
catch (Exception e)
{
Expand Down

0 comments on commit 3a52388

Please sign in to comment.