From 41aaa490c3fa8e5bcee87692d2d3483cd3acedab Mon Sep 17 00:00:00 2001 From: lakshaydiwan Date: Mon, 21 Oct 2024 16:50:14 +0530 Subject: [PATCH] fix:Simplify-error-handling(#3305) --- scripts/dashboard/build-dashboard.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/dashboard/build-dashboard.js b/scripts/dashboard/build-dashboard.js index 49fbf8b5d4f..397491decdf 100644 --- a/scripts/dashboard/build-dashboard.js +++ b/scripts/dashboard/build-dashboard.js @@ -45,11 +45,11 @@ async function getHotDiscussions(discussions) { }; } catch (e) { console.error( - `there was some issues while parsing this item: ${JSON.stringify( + `There was some issues while parsing this item: ${JSON.stringify( discussion )}` ); - throw e; + throw e; // Throw the error instead of logging } }) ); @@ -57,12 +57,14 @@ async function getHotDiscussions(discussions) { const filteredResult = result.filter(issue => issue.author !== 'asyncapi-bot'); return filteredResult.slice(0, 12); } + async function writeToFile(content) { writeFileSync( resolve(__dirname, '..', '..', 'dashboard.json'), JSON.stringify(content, null, ' ') ); } + async function mapGoodFirstIssues(issues) { return issues.map((issue) => ({ id: issue.id, @@ -87,7 +89,6 @@ function getLabel(issue, filter) { return result && result.name.split('/')[1]; } - function monthsSince(date) { const seconds = Math.floor((new Date() - new Date(date)) / 1000); // 2592000 = number of seconds in a month = 30 * 24 * 60 * 60 @@ -112,7 +113,7 @@ async function getDiscussions(query, pageSize, endCursor = null) { `limit = ${result.rateLimit.limit}`, `remaining = ${result.rateLimit.remaining}`, `resetAt = ${result.rateLimit.resetAt}` - ) + ); } const hasNextPage = result.search.pageInfo.hasNextPage; @@ -126,8 +127,10 @@ async function getDiscussions(query, pageSize, endCursor = null) { } } catch (e) { console.error(e); + throw e; // Throw the error instead of logging } } + async function getDiscussionByID(isPR, id) { try { let result = await graphql(isPR ? Queries.pullRequestById : Queries.issueById, { @@ -135,14 +138,14 @@ async function getDiscussionByID(isPR, id) { headers: { authorization: `token ${process.env.GITHUB_TOKEN}`, }, - - } - ); + }); return result; } catch (e) { console.error(e); + throw e; // Throw the error instead of logging } } + async function start() { try { const [issues, PRs, rawGoodFirstIssues] = await Promise.all([ @@ -157,10 +160,12 @@ async function start() { ]); writeToFile({ hotDiscussions, goodFirstIssues }); } catch (e) { - console.log('There were some issues parsing data from github.') + console.log('There were some issues parsing data from github.'); console.log(e); + throw e; // Throw the error instead of logging } } + start(); -module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID } \ No newline at end of file +module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID };