-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Write to log when error is shown in PR detail view #1199
Changes from 13 commits
1f6efe6
90b703f
40525e0
1815ca6
1d218ef
c8b1015
13ebf08
e7da47c
dc6c96f
d9b5c69
9ecdd2c
31b416a
791b2ca
582d7a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,18 +308,20 @@ public IObservable<string> ExtractFile( | |
} | ||
else | ||
{ | ||
sha = await gitClient.GetPullRequestMergeBase( | ||
repo, | ||
pullRequest.Base.RepositoryCloneUrl, | ||
pullRequest.Head.RepositoryCloneUrl, | ||
pullRequest.Base.Sha, | ||
pullRequest.Head.Sha, | ||
pullRequest.Base.Ref, | ||
pullRequest.Head.Ref); | ||
|
||
if (sha == null) | ||
try | ||
{ | ||
throw new NotFoundException($"Couldn't find merge base between {pullRequest.Base.Sha} and {pullRequest.Head.Sha}."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exception is now thrown from GetPullRequestMergeBase (with more info about what went wrong). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if an exception is thrown from a |
||
sha = await gitClient.GetPullRequestMergeBase( | ||
repo, | ||
pullRequest.Base.RepositoryCloneUrl, | ||
pullRequest.Head.RepositoryCloneUrl, | ||
pullRequest.Base.Sha, | ||
pullRequest.Head.Sha, | ||
pullRequest.Base.Ref, | ||
pullRequest.Head.Ref); | ||
} | ||
catch (NotFoundException ex) | ||
{ | ||
throw new NotFoundException($"The Pull Request file failed to load. Please check your network connection and click refresh to try again. If this issue persists, please let us know at support@github.com", ex); | ||
} | ||
} | ||
|
||
|
@@ -350,7 +352,7 @@ static bool HasPreamble(string file, Encoding encoding) | |
{ | ||
foreach (var b in encoding.GetPreamble()) | ||
{ | ||
if(b != stream.ReadByte()) | ||
if (b != stream.ReadByte()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look @shana, a space! ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
return false; | ||
} | ||
|
@@ -473,7 +475,7 @@ async Task<bool> IsBranchMarkedAsPullRequest(IRepository repo, string branchName | |
{ | ||
var prConfigKey = $"branch.{branchName}.{SettingGHfVSPullRequest}"; | ||
var value = ParseGHfVSConfigKeyValue(await gitClient.GetConfig<string>(repo, prConfigKey)); | ||
return value != null && | ||
return value != null && | ||
value.Item1 == pullRequest.Base.RepositoryCloneUrl.Owner && | ||
value.Item2 == pullRequest.Number; | ||
} | ||
|
@@ -550,4 +552,4 @@ static Tuple<string, int> ParseGHfVSConfigKeyValue(string value) | |
return null; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
using GitHub.UI; | ||
using LibGit2Sharp; | ||
using ReactiveUI; | ||
using NLog; | ||
|
||
namespace GitHub.ViewModels | ||
{ | ||
|
@@ -26,6 +27,8 @@ namespace GitHub.ViewModels | |
[PartCreationPolicy(CreationPolicy.NonShared)] | ||
public class PullRequestDetailViewModel : PanePageViewModelBase, IPullRequestDetailViewModel | ||
{ | ||
static readonly Logger log = LogManager.GetCurrentClassLogger(); | ||
|
||
readonly IModelService modelService; | ||
readonly IPullRequestService pullRequestsService; | ||
readonly IPullRequestSessionManager sessionManager; | ||
|
@@ -93,7 +96,7 @@ public PullRequestDetailViewModel( | |
Checkout = ReactiveCommand.CreateAsyncObservable( | ||
this.WhenAnyValue(x => x.CheckoutState) | ||
.Cast<CheckoutCommandState>() | ||
.Select(x => x != null && x.IsEnabled), | ||
.Select(x => x != null && x.IsEnabled), | ||
DoCheckout); | ||
Checkout.IsExecuting.Subscribe(x => isInCheckout = x); | ||
SubscribeOperationError(Checkout); | ||
|
@@ -351,6 +354,7 @@ public override void Initialize(ViewWithData data) | |
.ObserveOn(RxApp.MainThreadScheduler) | ||
.Catch<IPullRequestModel, Exception>(ex => | ||
{ | ||
log.Error("Error observing GetPullRequest", ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add logs when exception is displayed on UI. |
||
ErrorMessage = ex.Message.Trim(); | ||
IsLoading = IsBusy = false; | ||
return Observable.Empty<IPullRequestModel>(); | ||
|
@@ -460,6 +464,7 @@ public async Task Load(IRemoteRepositoryModel remoteRepository, IPullRequestMode | |
} | ||
catch (Exception ex) | ||
{ | ||
log.Error("Error loading PullRequestModel", ex); | ||
ErrorMessage = ex.Message.Trim(); | ||
} | ||
finally | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I understand why you'd want the details of the shas in the log, but this error message is incredibly cryptic, there is no way anyone is going to know what is going on with an error like this, and this is going to be displayed directly to a user where it's going to be completely useless.
We should have a message for the user, and another with more details for the log. If the log is only showing the message and stacktrace, we can set InnerException with the log details and have the outer exception be for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are all the callers of this method expecting an exception to be thrown and handling it properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Callers of this method previously turned the null into an exception themselves. I've also tested it by making this method always throw to check that nothing bad happens. The exception message is displayed as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what the user facing message should say? I suspect that for some reason, fetch doesn't always work or there is some race condition. I guess we could suggest thry try again or maybe refresh. I'll investagate...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, an indication of what the user action should be in the case of this error would be great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we go:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So "merge base" may be meaningless to a user, and try again might not be helpful either if the action that the user performed to get here isn't available from this screen.
What is the action that failed here? Opening a file? Showing the PR details? The first part of the message should say what was the action that failed.
What is try again? Refresh? Click on the PR button in the toolbar and then clicking on the PR again? The second part should say what the user can do on this screen to attempt to make it work.
Assuming it was the PR that failed to load, then we should probably say something like
The Pull Request failed to load. Please check your network connection and click refresh to try again.
Adjust accordingly for the failed action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I've chained it to variants of your suggestion above.
My concern was that we hide the real issue behind a workaround. I'm still keen to get to the bottom of what's going wrong. My hunch is that it's a race condition in gitlib2sharp. I'll see if I can reproduce the issue with some standalone code... 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we don't want to hide the issue in a workaround. If you're concerned about people not reporting it, you can add "If this issue persists, please let us know at support@github.com"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Also confirmed that nested exceptions appear in logs.