Skip to content
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

Closed

Conversation

lakshaydewan
Copy link

@lakshaydewan lakshaydewan commented Oct 21, 2024

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

  • New Features
    • Introduced new functions for writing content to a file and processing issue details.
  • Bug Fixes
    • Enhanced error handling across multiple functions to improve reliability.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request primarily enhance error handling in the scripts/dashboard/build-dashboard.js file by modifying several functions to throw errors instead of logging them. Additionally, two new asynchronous functions, writeToFile and mapGoodFirstIssues, have been introduced. The former writes content to a dashboard.json file, while the latter processes a list of issues to extract relevant details. The updates ensure that errors are propagated up the call stack, improving the overall robustness of the error handling mechanism.

Changes

File Change Summary
scripts/dashboard/build-dashboard.js - Updated getHotDiscussions, getDiscussions, getDiscussionByID, and start to throw errors instead of logging.
- Added new functions: async function writeToFile(content) and async function mapGoodFirstIssues(issues).
- Adjusted logging message formatting for consistency.

Possibly related issues

Poem

🐰 In the dashboard's code we play,
With errors thrown, we clear the way.
New functions hop, like bunnies bright,
Writing files, oh what a sight!
So let us cheer, for changes made,
In our code garden, joy won't fade! 🌼


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Oct 21, 2024

We require all PRs to follow Conventional Commits specification.
More details 👇🏼

 The subject "Simplify-error-handling(#3305)" found in the pull request title "fix: Simplify-error-handling(#3305)" should start with a lowercase character.

Copy link

netlify bot commented Oct 21, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 41aaa49
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/67163965329ee20009462f5e
😎 Deploy Preview https://deploy-preview-3310--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@asyncapi-bot
Copy link
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 40
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3310--asyncapi-website.netlify.app/

Copy link

@coderabbitai coderabbitai bot left a 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 message

The 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 errors

Accessing issue.author.login without checking if issue.author is not null may lead to a runtime error if author is null. To ensure robustness, add a null check similar to the one used in getHotDiscussions.

Apply this diff to fix the potential issue:

-    author: issue.author.login,
+    author: issue.author ? issue.author.login : '',

163-165: Use console.error instead of console.log for logging errors

In 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

📥 Commits

Files that changed from the base of the PR and between 3a8f69a and 41aaa49.

📒 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 appropriate

The code correctly logs a warning when the GitHub GraphQL rate limit is low.


130-133: Error rethrowing ensures proper propagation

By 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 strategy

The function now rethrows errors after logging, consistent with the new error handling approach.


171-171: Exporting updated module functions

The module.exports correctly includes the newly added mapGoodFirstIssues function for external use.

Comment on lines +60 to +67

async function writeToFile(content) {
writeFileSync(
resolve(__dirname, '..', '..', 'dashboard.json'),
JSON.stringify(content, null, ' ')
);
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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, ' ')
);
}

Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 52.91%. Comparing base (3a8f69a) to head (41aaa49).
Report is 32 commits behind head on master.

Files with missing lines Patch % Lines
scripts/dashboard/build-dashboard.js 0.00% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@sambhavgupta0705
Copy link
Member

@lakshaydewan can you please elaborate this issue a little more

@lakshaydewan
Copy link
Author

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..

@lakshaydewan lakshaydewan deleted the fix-error-handling branch November 1, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants