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 in build-dashboard.js(#3305) #3309

Closed
wants to merge 4 commits into from

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

  • Bug Fixes

    • Improved error handling in the dashboard build process with clearer and more descriptive error messages.
  • Chores

    • Updated the configuration for edit page links to point to the correct path.
    • Enhanced code clarity and readability in the dashboard script.
  • Documentation

    • Added context to error messages to assist with troubleshooting during parsing and fetching operations.

Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request involve two main modifications. The config/edit-page-config.json file has been updated to change a specific href attribute from a path related to pages to one related to markdown. In the scripts/dashboard/build-dashboard.js file, improvements have been made to error handling and code clarity, including the removal of an unused import, updates to error messages, and ensuring the completion of file writing operations before proceeding.

Changes

File Change Summary
config/edit-page-config.json Updated href attribute from https://github.com/asyncapi/website/blob/master/pages to https://github.com/asyncapi/website/blob/master/markdown.
scripts/dashboard/build-dashboard.js Enhanced error handling and code clarity; removed unused import; updated error messages; ensured writeToFile is awaited; added newline at end of file.

Possibly related issues

Poem

🐰 In the code where rabbits play,
Changes hop in a bright array.
Links to markdown, clear and neat,
Errors handled, oh what a treat!
With each tweak, our dashboard's bright,
Hopping forward, coding light! 🌟


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 👇🏼

 No release type found in pull request title "fix:Simplify error handling in build-dashboard.js(#3305)". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link

netlify bot commented Oct 21, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit eb7ca25
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6716335b2529fa000814efac
😎 Deploy Preview https://deploy-preview-3309--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-3309--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 (2)
scripts/dashboard/build-dashboard.js (2)

Line range hint 48-52: Improved error logging

The error message now provides more context, which is beneficial for debugging. Good improvement!

Consider adding the error object to the log for even more detailed debugging information:

console.error(
  `There were some issues while parsing this item: ${JSON.stringify(
    discussion
  )}`,
  e
);

155-172: LGTM: Improved error handling and code structure

The changes in this segment enhance the overall code quality:

  1. Added newlines improve code readability.
  2. Awaiting writeToFile ensures proper asynchronous execution.
  3. Updated error handling in the start function provides more context.
  4. The newline at the end of the file follows best practices.

These changes improve the code structure and error handling, making it more robust and maintainable.

Consider adding more specific error messages to distinguish between different types of errors that might occur in the start function. For example:

try {
  // ... existing code ...
} catch (e) {
  if (e.message.includes('API rate limit exceeded')) {
    console.error('GitHub API rate limit exceeded. Please try again later.');
  } else if (e.message.includes('Network error')) {
    console.error('Network error occurred while fetching data from GitHub.');
  } else {
    console.error('Unexpected error occurred while processing GitHub data:', e.message);
  }
  throw e;
}

This would provide even more detailed error information for debugging and user feedback.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

📒 Files selected for processing (2)
  • config/edit-page-config.json (1 hunks)
  • scripts/dashboard/build-dashboard.js (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • config/edit-page-config.json
🧰 Additional context used
🔇 Additional comments (5)
scripts/dashboard/build-dashboard.js (5)

26-30: LGTM: Improved code formatting

The changes in this segment improve the readability of the code without altering its functionality. This is a good practice for maintaining clean and easily understandable code.


94-95: LGTM: Improved clarity and precision

The added comment explains the calculation, enhancing code readability. Using Math.floor ensures we get a whole number of months, which is more appropriate for this context. These are good improvements.


Line range hint 115-129: LGTM: Improved error handling and code formatting

The changes in this segment enhance both the readability and the error handling of the code:

  1. The added newline after the console.log statement improves code formatting.
  2. The updated error handling in the catch block now provides more context by logging the error message before re-throwing it.

These changes will make debugging easier and improve the overall code quality.


132-147: LGTM: Enhanced error handling in getDiscussionByID

The changes in the getDiscussionByID function improve error handling and code readability:

  1. The error message now includes the discussion ID, providing more context for debugging.
  2. The error is properly re-thrown after logging, ensuring that the error propagates correctly.
  3. The added newline at the end of the function improves code formatting.

These changes will make it easier to diagnose issues related to fetching specific discussions.


Line range hint 1-172: Overall assessment: Good improvements with room for further enhancements

The changes in this file generally improve code quality, readability, and error handling. Key improvements include:

  1. Enhanced error messages providing more context for debugging.
  2. Better code formatting with added newlines.
  3. More precise calculations (e.g., using Math.floor for month calculations).

Areas for potential further improvement:

  1. Consider using asynchronous file writing to prevent blocking the event loop.
  2. Implement more granular error handling in the start function.
  3. Ensure consistent use of async/await throughout the file.

These changes align well with the PR objectives of simplifying and improving error handling. Good job on enhancing the maintainability and robustness of the code!

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

Consider using asynchronous file writing

The newline addition improves code readability. However, the change from fs.writeFile to writeFileSync makes the operation synchronous, which could potentially block the Node.js event loop, especially for large files.

Consider using the asynchronous fs.promises.writeFile instead:

const { promises: fsPromises } = require('fs');

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

This change would maintain the asynchronous nature of the operation and prevent potential blocking of the event loop.

@lakshaydewan
Copy link
Author

Will fix these issues and raise the final PR soon on this issue ..

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.

2 participants