Skip to content

Commit

Permalink
wrap drive info in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelbeltran committed Oct 15, 2024
1 parent 36f3666 commit 920229e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Raygun.Blazor/Models/EnvironmentDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ internal EnvironmentDetails(BrowserSpecs? specs, BrowserStats? stats)
// Couldn't find a way to obtain Model or Manufacturer.
DeviceName = Environment.MachineName,

// Convert Bytes to Gygabytes
// Each drive is listed individually
DiskSpaceFree = System.IO.DriveInfo.GetDrives().Select(d => Convert.ToDouble(d.TotalFreeSpace / 1024 / 1024 / 1024)).ToList(),
DiskSpaceFree = GetDiskSpaceFree(),

Locale = System.Globalization.CultureInfo.CurrentCulture.Name,
OSVersion = Environment.OSVersion.Version.ToString(),
Expand All @@ -251,6 +249,22 @@ internal EnvironmentDetails(BrowserSpecs? specs, BrowserStats? stats)
#pragma warning restore CA1416 // Validate platform compatibility
};

static private List<double> GetDiskSpaceFree()
{
try
{
// Convert Bytes to Gygabytes
// Each drive is listed individually
return System.IO.DriveInfo.GetDrives().Select(d => Convert.ToDouble(d.TotalFreeSpace / 1024 / 1024 / 1024)).ToList();
}
catch (Exception)
{
// If we can't get the disk space, return an empty list.
// e.g. "System.IO.IOException: The device is not ready" when running on CI.
return [];
}
}

#endregion

}
Expand Down

0 comments on commit 920229e

Please sign in to comment.