-
-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Simplify-error-handling(#3305) #3310
Conversation
WalkthroughThe changes in this pull request primarily enhance error handling in the Changes
Possibly related issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
We require all PRs to follow Conventional Commits specification.
|
✅ Deploy Preview for asyncapi-website ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3310--asyncapi-website.netlify.app/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
scripts/dashboard/build-dashboard.js (3)
48-52
: Correct the grammatical error in the error messageThe error message should read 'There were some issues while parsing this item' to be grammatically correct.
Apply this diff to fix the grammatical error:
-`There was some issues while parsing this item: ${JSON.stringify(discussion)}` +`There were some issues while parsing this item: ${JSON.stringify(discussion)}`
Line range hint
67-77
: Handle potential null 'issue.author' to avoid runtime errorsAccessing
issue.author.login
without checking ifissue.author
is not null may lead to a runtime error ifauthor
is null. To ensure robustness, add a null check similar to the one used ingetHotDiscussions
.Apply this diff to fix the potential issue:
- author: issue.author.login, + author: issue.author ? issue.author.login : '',
163-165
: Useconsole.error
instead ofconsole.log
for logging errorsIn the catch block, consider using
console.error
to log error messages, which is more appropriate for error logging and outputs to stderr.Apply this diff to improve error logging:
- console.log('There were some issues parsing data from github.'); - console.log(e); + console.error('There were some issues parsing data from github.'); + console.error(e);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- scripts/dashboard/build-dashboard.js (4 hunks)
🧰 Additional context used
🔇 Additional comments (4)
scripts/dashboard/build-dashboard.js (4)
116-116
: Logging of rate limit warning is appropriateThe code correctly logs a warning when the GitHub GraphQL rate limit is low.
130-133
: Error rethrowing ensures proper propagationBy rethrowing the error after logging, the function ensures that errors are properly propagated to the caller.
145-148
: Error rethrowing aligns with updated error handling strategyThe function now rethrows errors after logging, consistent with the new error handling approach.
171-171
: Exporting updated module functionsThe
module.exports
correctly includes the newly addedmapGoodFirstIssues
function for external use.
|
||
async function writeToFile(content) { | ||
writeFileSync( | ||
resolve(__dirname, '..', '..', 'dashboard.json'), | ||
JSON.stringify(content, null, ' ') | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use asynchronous file write operation for non-blocking I/O
In the writeToFile
async function, you're using writeFileSync
, which is synchronous and blocks the event loop. To keep the code non-blocking and efficient, consider using the asynchronous version fs.promises.writeFile
.
Apply this diff to fix the issue:
-const { writeFileSync } = require('fs');
+const { writeFile } = require('fs/promises');
...
-async function writeToFile(content) {
- writeFileSync(
+async function writeToFile(content) {
+ await writeFile(
resolve(__dirname, '..', '..', 'dashboard.json'),
JSON.stringify(content, null, ' ')
);
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
async function writeToFile(content) { | |
writeFileSync( | |
resolve(__dirname, '..', '..', 'dashboard.json'), | |
JSON.stringify(content, null, ' ') | |
); | |
} | |
const { writeFile } = require('fs/promises'); | |
async function writeToFile(content) { | |
await writeFile( | |
resolve(__dirname, '..', '..', 'dashboard.json'), | |
JSON.stringify(content, null, ' ') | |
); | |
} |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3310 +/- ##
==========================================
- Coverage 53.17% 52.91% -0.27%
==========================================
Files 21 21
Lines 598 601 +3
==========================================
Hits 318 318
- Misses 280 283 +3 ☔ View full report in Codecov by Sentry. |
@lakshaydewan can you please elaborate this issue a little more |
The issue was with the initial error handling where we were only catching the errors in lower level but the suggestion was to throw errors from lower level to upper error managers deliberately so inside the catch block we throw the same error that was caught.. |
This PR improves the error handling in the build-dashboard.js script by directly throwing errors instead of using Promise.reject(e). This makes the asynchronous functions more idiomatic and easier to maintain.
Key changes:
Replaced instances of Promise.reject(e) with throw e to ensure consistent error handling.
Cleaned up the error logging to provide clearer and more actionable error messages.
These changes improve the readability and robustness of the code, especially in cases where asynchronous functions need better error propagation.
Feel free to provide feedback or suggest any additional improvements!
Summary by CodeRabbit