Skip to content

Commit 736ba26

Browse files
committed
Fix potential null exceptions on GH Backup (fix #3886)
1 parent 05aec1d commit 736ba26

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/UniGetUI/Services/GitHubBackupService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task UploadPackageBundle(string bundleContents)
3838
User user = await GHClient.User.Current();
3939

4040
var candidates = await GHClient.Gist.GetAllForUser(user.Login);
41-
Gist? existingBackup = candidates?.FirstOrDefault(g => g.Description.EndsWith(GistDescription_EndingKey));
41+
Gist? existingBackup = candidates?.FirstOrDefault(g => g?.Description?.EndsWith(GistDescription_EndingKey) ?? false);
4242

4343
if (existingBackup is null)
4444
{
@@ -96,7 +96,7 @@ public async Task<IEnumerable<string>> GetAvailableBackups()
9696
User user = await GHClient.User.Current();
9797

9898
var candidates = await GHClient.Gist.GetAllForUser(user.Login);
99-
Gist? existingBackup = candidates?.FirstOrDefault(g => g.Description.EndsWith(GistDescription_EndingKey));
99+
Gist? existingBackup = candidates?.FirstOrDefault(g => g?.Description?.EndsWith(GistDescription_EndingKey) ?? false);
100100

101101
return existingBackup?.Files
102102
.Where(f => f.Key.StartsWith(PackageBackup_StartingKey))
@@ -115,7 +115,7 @@ public async Task<IEnumerable<string>> GetAvailableBackups()
115115
User user = await GHClient.User.Current();
116116

117117
var candidates = await GHClient.Gist.GetAllForUser(user.Login);
118-
Gist? existingBackup = candidates?.FirstOrDefault(g => g.Description.EndsWith(GistDescription_EndingKey));
118+
Gist? existingBackup = candidates?.FirstOrDefault(g => g?.Description?.EndsWith(GistDescription_EndingKey) ?? false);
119119
if (existingBackup is null)
120120
throw new Exception($"The backup {backupName} was not found, yet this name was passed by argument");
121121

0 commit comments

Comments
 (0)