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

server: improve error message when client is not present #1242

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

dyc3
Copy link
Owner

@dyc3 dyc3 commented Jan 19, 2024

No description provided.

Copy link
Contributor

coderabbitai bot commented Jan 19, 2024

Walkthrough

The update to server/app.ts enhances the server's user-friendliness by addressing a common setup oversight. When the server can't find the necessary client files, it now responds with a helpful error message. This message advises the developer to run a build command, likely preventing confusion and streamlining the troubleshooting process.

Changes

File Summary
server/app.ts Improved error handling for missing client distribution folder; now advises yarn build.

Poem

🐇 In the server's burrow, deep in the code,
🚫 A 404 was found on the road.
🛠️ "Run 'yarn build'," the rabbit suggests,
🌟 With each fix and tweak, our app only gets better!

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@dyc3 dyc3 added the server Improvements or additions to the server label Jan 19, 2024
Copy link
Contributor

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 15b055b and b85cf98.
Files selected for processing (1)
  • server/app.ts (1 hunks)
Additional comments: 5
server/app.ts (5)
  • 204-209: The addition of a specific warning message and a 404 error response when the client's distribution folder is not found is a good improvement for user experience.
  • 204-209: The error message is clear and instructive, and the use of HTTP 404 is appropriate for the situation where the client files are not found. Ensure that this change does not interfere with any other routes that might be serving files or content from the ../client/dist directory.
Verification successful

The review comment's concern has been addressed. The server's existing functionality to serve static files from the ../client/dist directory is conditional on the presence of the folder, and the new error handling logic only comes into play when the folder is missing. There should be no interference with existing routes as long as the client's distribution folder exists.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that no other routes are serving content from the client's distribution folder.
rg --type ts "express.static" --context 5 server/app.ts

Length of output: 303

* 204-209: No sensitive information is exposed in the new error message, and it does not introduce any security concerns. * 204-209: The file system check for the client's distribution folder is done only once during the server initialization, which is good for performance as it avoids repeated checks on each request. * 204-209: The new error handling for the missing client distribution folder is consistent with the application's error handling strategy, providing clear and actionable feedback to the user.

Comment on lines +204 to +209
log.warn("no dist folder found, run `yarn build` to build the client");
app.get("*", (req, res) => {
res.status(404).send(
"File not found - Client files not found. Run `yarn build` to build the client."
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider abstracting the relative path to the client's distribution folder and the error message into configuration settings or constants to improve maintainability and avoid duplication.

- log.warn("no dist folder found, run `yarn build` to build the client");
- res.status(404).send(
-   "File not found - Client files not found. Run `yarn build` to build the client."
- );
+ const clientDistPath = "../client/dist";
+ const buildClientMessage = "File not found - Client files not found. Run `yarn build` to build the client.";
+ log.warn(`no ${clientDistPath} folder found, run \`yarn build\` to build the client`);
+ res.status(404).send(buildClientMessage);

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.

Suggested change
log.warn("no dist folder found, run `yarn build` to build the client");
app.get("*", (req, res) => {
res.status(404).send(
"File not found - Client files not found. Run `yarn build` to build the client."
);
});
const clientDistPath = "../client/dist";
const buildClientMessage = "File not found - Client files not found. Run `yarn build` to build the client.";
log.warn(`no ${clientDistPath} folder found, run \`yarn build\` to build the client`);
app.get("*", (req, res) => {
res.status(404).send(buildClientMessage);
});

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (15b055b) 0.0000% compared to head (b85cf98) 61.5425%.

Files Patch % Lines
server/app.ts 0.0000% 3 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           master      #1242         +/-   ##
===============================================
+ Coverage        0   61.5425%   +61.5425%     
===============================================
  Files           0        117        +117     
  Lines           0       9413       +9413     
  Branches        0       1155       +1155     
===============================================
+ Hits            0       5793       +5793     
- Misses          0       3620       +3620     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cypress bot commented Jan 19, 2024

Passing run #846 ↗︎

0 71 1 0 Flakiness 0

Details:

Merge b85cf98 into 15b055b...
Project: OpenTogetherTube Commit: 7602ab6921 ℹ️
Status: Passed Duration: 03:30 💡
Started: Jan 19, 2024 7:24 PM Ended: Jan 19, 2024 7:28 PM

Review all test suite changes for PR #1242 ↗︎

@dyc3 dyc3 merged commit 5195a36 into master Jan 19, 2024
17 of 18 checks passed
@dyc3 dyc3 deleted the missing-client-error branch January 19, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Improvements or additions to the server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant