C#: Log information about asset file read errors.

This commit is contained in:
Michael Nebel
2023-11-17 15:40:58 +01:00
parent cd9786a952
commit 7531852ea6

View File

@@ -143,14 +143,31 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
}
}
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;
}
}
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;
}