Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Display GitHub error message when module sync fails #348

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamlundrigan
Copy link
Contributor

Catch the RuntimeException thrown by EdpGithub and send it back to the user.

image

Two notes:

  • I tried to test it but failed. I couldn't find the right incantation to get PHPUnit's mock builder to build a suitable replacement for EdpGithub's RepositoryCollection. Perhaps someone with a kinder disposition towards mock builder could try?
  • I looked through EdpGithub and GitHub's docs and I don't see any case where sensitive information could be leaked through the failure message, so IMO it should be fine to just dump it back to the user for now.

@ins0
Copy link
Contributor

ins0 commented Jan 28, 2015

maybe we move the error catch also to the RepositoryRetreiver class?

mocked a error case with the github client - helpful?

@adamlundrigan
Copy link
Contributor Author

It's a largely cosmetic change anyway so I didn't put too much effort into writing a test for it...that whole controller is untested and needs a refactor to make that feasible. You're right though, if I mock the client instead of the collection I'd likely have an easier time.

$repositories = $this->fetchModules($repos);
$viewModel->setVariable('repositories', $repositories);
} catch (GithubException $ex) {
$viewModel->setVariable('error_message', $ex->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

camelCase? Also, above.

@localheinz
Copy link
Member

@adamlundrigan

Not sure about passing through the actual exception message, as you pointed it out, but looks good to me!

@adamlundrigan
Copy link
Contributor Author

@localheinz thanks for the reivew. I've fixed the items you pointed out.

As for returning the exception message it's not ideal but it's a good stop-gap to keep the spinner from spinning forever if there is a problem with the sync. Ideally EdpGithub or the RepositoryRetriever service would throw distinguishable exceptions (or at least exception messages we know to be safe to send back to the user)

$repositories = $this->fetchModules($repos);
$viewModel->setVariable('repositories', $repositories);
} catch (GithubException $ex) {
$viewModel->setVariable('errorMessage', $ex->getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

You should still set a 503 response code, even if the page is correctly generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably a good idea, but outside the scope of this PR. The github sync process needs to be rewritten (#349) and @ins0 is working on the user panel stuff in #351

@Ocramius
Copy link
Member

I'd still ask for a unit test of this functionality (mock with ->throwsException())

@adamlundrigan
Copy link
Contributor Author

@Ocramius I mocked all the things; there are now four test cases covering the changes made in this PR

@localheinz
Copy link
Member

@adamlundrigan

Needs a rebase!

@Ocramius
Copy link
Member

This needs another rebase, sorry for letting it slip through, @adamlundrigan :(

@GeeH
Copy link
Contributor

GeeH commented Feb 20, 2015

Can this be merged

@GeeH
Copy link
Contributor

GeeH commented Apr 24, 2015

Ping @Ocramius @adamlundrigan

@Ocramius
Copy link
Member

It needs a rebase before it can be merged

@adamlundrigan
Copy link
Contributor Author

                                                                                  I'll take a look today

@adamlundrigan
Copy link
Contributor Author

The code had changed so much I ditched my original and implemented it fresh, integrating your suggestions:

  • RepositoryRetriever now catches the exception and returns false (@ins0), which is more consistent with the way other methods in RepositoryRetriever behave.
  • indexAction and listAction return 503 when an error is detected (@Ocramius)
  • The actual exception message is no longer passed through to the user (@localheinz)
  • Swapped out $.load for $.ajax in the views as the former only handles success conditions.

I was no longer able to reproduce the original API limit exceptions against GitHub (kudos to whomever fixed the sync 👍) but the principle behind the change is the same: catch any exception coming from EdpGithub and dump out an error message to the user.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants