-
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
Conversation
Previously null was being returned and information about what went wrong was lost.
27ce99a
to
1815ca6
Compare
@@ -350,7 +345,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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Add logs when exception is displayed on UI.
|
||
if (sha == null) | ||
{ | ||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if an exception is thrown from a Observable.Defer(async () =>
?
{ | ||
await gitClient.GetPullRequestMergeBase(repo, baseUri, headUri, baseSha, headSha, baseRef, headRef); | ||
} | ||
catch (NotFoundException) { } |
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.
Ignoring an exception in a test is weird. Is it supposed to throw or not?
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.
It's certainly a bit unusual. The method it's calling would previously return a null when a comment couldn't be fetched/found. It now throws an exception.
The test is to check whether or not Fetch
was called. It doesn't care about the exception or exception message. There is another test for that.
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.
Ah ok, in that case we should probably document that with a comment, so we know in a year from now what the assumption here is.
@@ -394,7 +394,7 @@ public Task<bool> IsModified(IRepository repository, string path, byte[] content | |||
baseCommit = repo.Lookup<Commit>(baseSha); | |||
if (baseCommit == null) | |||
{ | |||
return null; | |||
throw new NotFoundException($"Couldn't find {baseSha} after fetching from {baseCloneUrl}:{baseRef}."); |
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.
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.
This method now throws `NotFoundException` rather than returning null.
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.
These commits were originally intended to help track down the 'Couldn't find merge base' issue #1190. This issue hasn't been resolved yet, but I think having the extra logging and exception detail will be useful stand alone.
When the following error is displayed, the exception detail will also be written to the log.