Skip to content

Commit

Permalink
Fix error reporting for loading repositories from GitHub
Browse files Browse the repository at this point in the history
This change fixes reporting errors in the functionality to clone git repositories: It removes an unconditional 'catch' statement that could swallow exceptions from 'LibGit2Sharp'.
This change also fixed the `ArgumentNullException` on Ubuntu 22.04 described at #19

For the docker image described there, we now get this more specific error:
```
LibGit2Sharp.LibGit2SharpException: could not load ssl libraries
```
  • Loading branch information
Viir committed Oct 5, 2022
1 parent 81e61aa commit cda8b8e
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 220 deletions.
28 changes: 17 additions & 11 deletions implement/elm-fullstack/Pine/CacheByFileName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ namespace Pine;

public record CacheByFileName(string CacheDirectory)
{
public byte[] GetOrUpdate(string fileName, System.Func<byte[]> getNew)
public byte[] GetOrUpdate(string fileName, System.Func<byte[]> getNew) =>
GetOrTryAdd(fileName, getNew)!;

public byte[]? GetOrTryAdd(string fileName, System.Func<byte[]?> tryBuild)
{
var cacheFilePath = Path.Combine(CacheDirectory, fileName);

Expand All @@ -17,20 +20,23 @@ public byte[] GetOrUpdate(string fileName, System.Func<byte[]> getNew)
catch { }
}

var file = getNew();
var file = tryBuild();

try
if (file is not null)
{
var directory = Path.GetDirectoryName(cacheFilePath);
try
{
var directory = Path.GetDirectoryName(cacheFilePath);

if (directory != null)
Directory.CreateDirectory(directory);
if (directory != null)
Directory.CreateDirectory(directory);

File.WriteAllBytes(cacheFilePath, file);
}
catch (System.Exception e)
{
System.Console.WriteLine("Failed to write cache entry: " + e.ToString());
File.WriteAllBytes(cacheFilePath, file);
}
catch (System.Exception e)
{
System.Console.WriteLine("Failed to write cache entry: " + e.ToString());
}
}

return file;
Expand Down
Loading

0 comments on commit cda8b8e

Please sign in to comment.