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

Write to log when error is shown in PR detail view #1199

Merged
merged 14 commits into from
Aug 25, 2017

Conversation

jcansdale
Copy link
Collaborator

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.
couldnt find merge base

@@ -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())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look @shana, a space! ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejoice

@@ -351,6 +354,7 @@ public override void Initialize(ViewWithData data)
.ObserveOn(RxApp.MainThreadScheduler)
.Catch<IPullRequestModel, Exception>(ex =>
{
log.Error("Error observing GetPullRequest", ex);
Copy link
Collaborator Author

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.

@jcansdale jcansdale requested review from grokys and shana August 25, 2017 09:24

if (sha == null)
{
throw new NotFoundException($"Couldn't find merge base between {pullRequest.Base.Sha} and {pullRequest.Head.Sha}.");
Copy link
Collaborator Author

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).

Copy link
Collaborator Author

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) { }
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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}.");
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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...

Copy link
Contributor

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!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go:
image

Copy link
Contributor

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.

Copy link
Collaborator Author

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... 😄

Copy link
Contributor

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"

Copy link
Collaborator Author

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.

shana
shana previously approved these changes Aug 25, 2017
Copy link
Contributor

@shana shana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jcansdale jcansdale merged commit 19bf7aa into master Aug 25, 2017
@jcansdale jcansdale deleted the jcansdale/add-more-logging branch August 25, 2017 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants