Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit e7da47c

Browse files
committed
Show friendly message to user but still log detail
1 parent 13ebf08 commit e7da47c

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,21 @@ public IObservable<string> ExtractFile(
308308
}
309309
else
310310
{
311-
sha = await gitClient.GetPullRequestMergeBase(
312-
repo,
313-
pullRequest.Base.RepositoryCloneUrl,
314-
pullRequest.Head.RepositoryCloneUrl,
315-
pullRequest.Base.Sha,
316-
pullRequest.Head.Sha,
317-
pullRequest.Base.Ref,
318-
pullRequest.Head.Ref);
311+
try
312+
{
313+
sha = await gitClient.GetPullRequestMergeBase(
314+
repo,
315+
pullRequest.Base.RepositoryCloneUrl,
316+
pullRequest.Head.RepositoryCloneUrl,
317+
pullRequest.Base.Sha,
318+
pullRequest.Head.Sha,
319+
pullRequest.Base.Ref,
320+
pullRequest.Head.Ref);
321+
}
322+
catch (NotFoundException ex)
323+
{
324+
throw new NotFoundException($"Couldn't find merge base. Please check your network connection and try again.", ex);
325+
}
319326
}
320327

321328
var file = await ExtractToTempFile(repo, pullRequest.Number, sha, fileName, encoding);

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ public async Task<string> GetPullRequestMergeBase(ILocalRepositoryModel reposito
126126
var headUrl = pullRequest.Head.RepositoryCloneUrl;
127127
var baseRef = pullRequest.Base.Ref;
128128
var headRef = pullRequest.Head.Ref;
129-
mergeBase = await gitClient.GetPullRequestMergeBase(repo, baseUrl, headUrl, baseSha, headSha, baseRef, headRef);
129+
try
130+
{
131+
mergeBase = await gitClient.GetPullRequestMergeBase(repo, baseUrl, headUrl, baseSha, headSha, baseRef, headRef);
132+
}
133+
catch (NotFoundException ex)
134+
{
135+
throw new NotFoundException("Couldn't find merge base. Please check your network connection and try again.", ex);
136+
}
130137

131138
return mergeBaseCache[key] = mergeBase;
132139
}

src/UnitTests/GitHub.App/Services/PullRequestServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public async Task ExtractBase_MergeBaseAvailable_UseMergeBaseSha()
5454
}
5555

5656
[Fact]
57-
public async void MergeBaseNotAvailable_ThrowsFileNotFoundException()
57+
public async void MergeBaseNotAvailable_ThrowsNotFoundException()
5858
{
5959
var baseFileContent = "baseFileContent";
6060
var headFileContent = "headFileContent";
@@ -64,7 +64,7 @@ public async void MergeBaseNotAvailable_ThrowsFileNotFoundException()
6464
var headSha = "headSha";
6565
var mergeBaseSha = null as string;
6666
var head = false;
67-
var expectMessage = $"Couldn't find merge base between {baseSha} and {headSha}.";
67+
var expectMessage = $"Couldn't find merge base. Please check your network connection and try again.";
6868
var mergeBaseException = new NotFoundException(expectMessage);
6969

7070
var ex = await Assert.ThrowsAsync<NotFoundException>(() => ExtractFile(baseSha, baseFileContent, headSha, headFileContent, mergeBaseSha, mergeBaseFileContent,

0 commit comments

Comments
 (0)