From 77da6887f7d234cad40df74f68dde3e62a98ef22 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Wed, 11 Mar 2020 09:01:44 +0100 Subject: [PATCH] build(dev-infra): handle async failures in `get-data.ts` (#36007) Wrap the await block in a try/catch so not to have unhandled promise rejections. PR Close #36007 --- tools/contributing-stats/get-data.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/contributing-stats/get-data.ts b/tools/contributing-stats/get-data.ts index c4cf31028b..6bd6267ee2 100644 --- a/tools/contributing-stats/get-data.ts +++ b/tools/contributing-stats/get-data.ts @@ -232,12 +232,18 @@ function buildQueryAndParams(username: string, date: string) { * of the organization. */ async function run(date: string) { - console.info(['Username'].concat(buildQueryAndParams('', date).labels).join(',')); + try { + const allOrgMembers = await getAllOrgMembers(); + console.info(['Username', ...buildQueryAndParams('', date).labels].join(',')); - for (let username of await getAllOrgMembers()) { - const results = await graphql(buildQueryAndParams(username, date).query); - const values = Object.values(results).map(result => `${result.issueCount}`); - console.info([username].concat(values).join(',')); + for (const username of allOrgMembers) { + const results = await graphql(buildQueryAndParams(username, date).query); + const values = Object.values(results).map(result => `${result.issueCount}`); + console.info([username, ...values].join(',')); + } + } catch (error) { + console.error(`Error: ${error.message}`); + process.exit(1); } }