Skip to content

Commit 97bbb12

Browse files
authored
Merge pull request #6838 from hvitved/csharp/enumerate-files-dir-not-found
C#: Make `GetCSharpArgsLogs` robust against log directory not existing
2 parents df8c399 + 61973c3 commit 97bbb12

File tree

1 file changed

+12
-2
lines changed
  • csharp/extractor/Semmle.Extraction.CSharp/Extractor

1 file changed

+12
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Extractor/Extractor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,18 @@ public static string GetCSharpArgsLogPath(string hash) =>
492492
/// <summary>
493493
/// Gets a list of all `csharp.{hash}.txt` files currently written to the log directory.
494494
/// </summary>
495-
public static IEnumerable<string> GetCSharpArgsLogs() =>
496-
Directory.EnumerateFiles(GetCSharpLogDirectory(), "csharp.*.txt");
495+
public static IEnumerable<string> GetCSharpArgsLogs()
496+
{
497+
try
498+
{
499+
return Directory.EnumerateFiles(GetCSharpLogDirectory(), "csharp.*.txt");
500+
}
501+
catch (DirectoryNotFoundException)
502+
{
503+
// If the directory does not exist, there are no log files
504+
return Enumerable.Empty<string>();
505+
}
506+
}
497507

498508
private static string GetCSharpLogDirectory()
499509
{

0 commit comments

Comments
 (0)