Skip to content

Commit

Permalink
C#: Log information about asset file read errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnebel committed Nov 17, 2023
1 parent cd9786a commit 7531852
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,31 @@ public bool TryParse(string json, DependencyContainer dependencies)
}
}

private static bool TryReadAllText(string path, ProgressMonitor progressMonitor, out string content)
{
try
{
content = File.ReadAllText(path);
return true;
}
catch (Exception e)
{
progressMonitor.LogInfo($"Failed to read assets file '{path}': {e.Message}");
content = "";
return false;
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

public static DependencyContainer GetCompilationDependencies(ProgressMonitor progressMonitor, IEnumerable<string> assets)
{
var parser = new Assets(progressMonitor);
var dependencies = new DependencyContainer();
assets.ForEach(asset =>
{
var json = File.ReadAllText(asset);
parser.TryParse(json, dependencies);
if (TryReadAllText(asset, progressMonitor, out var json))
{
parser.TryParse(json, dependencies);
}
});
return dependencies;
}
Expand Down

0 comments on commit 7531852

Please sign in to comment.