From b61b8fbdb88a64192ca837550b7a53e6c27a90e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dandelion=20Man=C3=A9?= Date: Fri, 27 Jul 2018 13:27:40 -0700 Subject: [PATCH] Improve error messages when GitHub query fails (#536) Currently, the GitHub graph fetcher will characteristically fail if: 1. it times out GitHub's server 2. it triggers the semidocumented abuse detection mechanism In case 1, an intelligible error is posted to the console. In case 2, it produces an unintelligible TypeError, because the response is not a valid GraphQL response (the error field is not populated; it has a custom message instead). As of this commit, we gracefully catch both cases, and print a message to console directing the user to #350, which has context on GitHub query failures. This new catch works because in case 2, the data field is empty, so we now properly recognize `x.data === undefined` as an error case. Thanks to @wchargin for the investigatory work behind this commit. Fixes #223. Test plan: We don't have unit tests that cover this case, but I did manually test it by asking GitHub to fetch `ipfs/go-ipfs`, which consistently fails. I also tested it by using an invalid length-40 GitHub API token. --- src/plugins/github/fetchGithubRepo.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/github/fetchGithubRepo.js b/src/plugins/github/fetchGithubRepo.js index f29cf08..dddcd40 100644 --- a/src/plugins/github/fetchGithubRepo.js +++ b/src/plugins/github/fetchGithubRepo.js @@ -74,7 +74,15 @@ function postQuery({body, variables}, token) { }) .then((x) => x.json()) .then((x) => { - if (x.errors) { + if (x.errors || x.data === undefined) { + console.error( + "GitHub query failed! We're tracking these issues at " + + "https://github.com/sourcecred/sourcecred/issues/350.\n" + + "If the error is a timeout or abuse rate limit, you can " + + "try loading a smaller repo, or trying again in a few minutes.\n" + + "The actual failed response can be found below:\n" + + "=================================================" + ); return Promise.reject(x); } return Promise.resolve(x.data);