Skip to content

Commit 7531852

Browse files
committed
C#: Log information about asset file read errors.
1 parent cd9786a commit 7531852

File tree

1 file changed

+19
-2
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching

1 file changed

+19
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Assets.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,31 @@ public bool TryParse(string json, DependencyContainer dependencies)
143143
}
144144
}
145145

146+
private static bool TryReadAllText(string path, ProgressMonitor progressMonitor, out string content)
147+
{
148+
try
149+
{
150+
content = File.ReadAllText(path);
151+
return true;
152+
}
153+
catch (Exception e)
154+
{
155+
progressMonitor.LogInfo($"Failed to read assets file '{path}': {e.Message}");
156+
content = "";
157+
return false;
158+
}
159+
}
160+
146161
public static DependencyContainer GetCompilationDependencies(ProgressMonitor progressMonitor, IEnumerable<string> assets)
147162
{
148163
var parser = new Assets(progressMonitor);
149164
var dependencies = new DependencyContainer();
150165
assets.ForEach(asset =>
151166
{
152-
var json = File.ReadAllText(asset);
153-
parser.TryParse(json, dependencies);
167+
if (TryReadAllText(asset, progressMonitor, out var json))
168+
{
169+
parser.TryParse(json, dependencies);
170+
}
154171
});
155172
return dependencies;
156173
}

0 commit comments

Comments
 (0)