digital-land / submit

0 stars 1 forks source link

express error handling #657

Closed rosado closed 4 days ago

rosado commented 1 week ago

What type of PR is this? (check all applicable)

Description

Due to the combination of the following:

We sometimes end up with unhandled errors (e.g. in fetchEntry()).

We can't switch to 5.x (at least not easily, the wizard library relies on something that broke between 4.x and 5.x), so we have to handle this explicitly. This PR adds a wrapper middleware to handle such errors for the few cases where fetchOne()/fetchMany() isn't used. 500 error is returned now.

Also, moves some of the data fetches to use generic middleware and removes some dead code.

Related Tickets & Documents

No ticket, but related Sentry error

Added/updated tests?

Summary by CodeRabbit

Release Notes

github-actions[bot] commented 1 week ago

Coverage Report

Status Category Percentage Covered / Total
šŸ”µ Lines 67.93% 4415 / 6499
šŸ”µ Statements 67.93% 4415 / 6499
šŸ”µ Functions 67.37% 190 / 282
šŸ”µ Branches 82.4% 548 / 665
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/middleware/issueDetails.middleware.js 80.34% 62.5% 41.66% 80.34% 51-63, 76-99, 207-213, 227-230, 233-236, 240-244
src/middleware/middleware.builders.js 87.13% 88.57% 83.33% 87.13% 36, 104-115, 128-141, 258-261, 282-290
src/middleware/overview.middleware.js 86.58% 85.71% 57.14% 86.58% 10-12, 24, 32, 46-50, 68-69, 116-125
src/serverSetup/errorHandlers.js 0% 0% 0% 0% 1-46
src/services/performanceDbApi.js 64.47% 92.59% 35.71% 64.47% 49-77, 114-116, 179-183, 234-240, 251-264, 273-293, 297-305, 314-326, 337-364, 374-379
Generated in workflow #293 for commit c77c3e0 by the Vitest Coverage Report Action
coderabbitai[bot] commented 1 week ago

Walkthrough

The changes primarily involve refactoring middleware functions across several files to enhance modularity and error handling. Key modifications include the introduction of new utility functions for handling promise rejections and updates to existing middleware to utilise these new functions. The structure of data being handled has also been modified, particularly in how counts are represented. Overall, the changes aim to streamline the middleware architecture and improve error management.

Changes

File Change Summary
src/middleware/issueDetails.middleware.js Refactored fetchIssues and fetchIssueEntitiesCount to use fetchMany and fetchOne. Updated handling of issueEntitiesCount to be an object. Minor adjustments to request parameter destructuring.
src/middleware/middleware.builders.js Added safeFn for error handling and handleRejections to wrap middleware functions for promise rejection management.
src/middleware/overview.middleware.js Wrapped fetchEntityCounts with handleRejections to improve error handling. No changes to function logic.
src/serverSetup/errorHandlers.js Added checks for res.headersSent in error handling and 404 middleware to prevent modifying responses after headers are sent.
src/services/performanceDbApi.js Introduced issuesQueryLimit, refactored methods to accept request objects for queries, and removed getEntityCount. Enhanced error handling in getEntityCounts.
test/unit/middleware/issueDetails.middleware.test.js Updated tests to reflect changes in issueEntitiesCount structure from integer to object with count property.
test/unit/middleware/middleware.builders.test.js Added tests for the new handleRejections function to ensure proper error handling and invocation of wrapped middleware.

Possibly related PRs

Suggested reviewers

šŸ° In the meadow, changes bloom,
Middleware now dispels the gloom.
With rejections handled right,
Errors fade out of sight.
Count the issues, one, two, three,
A modular world, hop with glee! šŸŒ¼


šŸ“œ Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
šŸ“„ Commits Reviewing files that changed from the base of the PR and between 0c8875cf920226d5fa8e782290f90c3c4e76608a and c77c3e0d7ac4a9920ec34e25cc17f62811b2c1a9.
šŸ“’ Files selected for processing (1) * `src/middleware/overview.middleware.js` (2 hunks)
šŸš§ Files skipped from review as they are similar to previous changes (1) * src/middleware/overview.middleware.js

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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
šŸŖ§ Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
neilfwar commented 2 days ago

showing as done - but no end date?