Skip to content

Commit

Permalink
update grammar: improve reporting of exceeded github rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli committed Feb 12, 2018
1 parent c9fc911 commit 6b31642
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions build/npm/update-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function download(url, redirectCount) {
response.on('data', function (data) {
content += data.toString();
}).on('end', function () {
if (response.statusCode === 403 && response.headers['x-ratelimit-remaining'] === '0') {
e('GitHub API rate exceeded. Set GITHUB_TOKEN environment variable to increase rate limit.');
return;
}
let count = redirectCount || 0;
if (count < 5 && response.statusCode >= 300 && response.statusCode <= 303 || response.statusCode === 307) {
let location = response.headers['location'];
Expand Down Expand Up @@ -64,12 +68,8 @@ function getCommitSha(repoId, repoPath) {
commitDate: lastCommit.commit.author.date
});
} catch (e) {
console.error("Failed extracting the SHA: " + content);
return Promise.resolve(null);
return Promise.reject(new Error("Failed extracting the SHA: " + content));
}
}, function () {
console.error('Failed loading ' + commitInfo);
return Promise.resolve(null);
});
}

Expand All @@ -86,8 +86,7 @@ exports.update = function (repoId, repoPath, dest, modifyGrammar, version = 'mas
} else if (ext === '.json') {
grammar = JSON.parse(content);
} else {
console.error('Unknown file extension: ' + ext);
return;
return Promise.reject(new Error(('Unknown file extension: ' + ext)));
}
if (modifyGrammar) {
modifyGrammar(grammar);
Expand Down Expand Up @@ -118,11 +117,14 @@ exports.update = function (repoId, repoPath, dest, modifyGrammar, version = 'mas
console.log('Updated ' + path.basename(dest));
}
} catch (e) {
console.error(e);
return Promise.reject(e);
}
});

}, console.error);
}, console.error).catch(e => {
console.error(e);
process.exit(1);
});
};

if (path.basename(process.argv[1]) === 'update-grammar.js') {
Expand Down

0 comments on commit 6b31642

Please sign in to comment.