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: correctly set error code in the debug mode #198

Merged
merged 4 commits into from
Feb 3, 2024

Conversation

rustatian
Copy link
Member

@rustatian rustatian commented Feb 2, 2024

Reason for This PR

closes: roadrunner-server/roadrunner#1843

Description of Changes

  • Correctly handle undefined errors.
image

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • Chores
    • Updated .gitignore to exclude specific test certificates.
  • Refactor
    • Improved error handling in the application for enhanced response customization.
  • New Features
    • Introduced new configuration settings for server application in tests.
  • Tests
    • Updated server address and version in test configurations.
    • Introduced a new test to cover a specific bug scenario.
    • Added a PHP script for testing a \RuntimeException.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added bug Something isn't working enhancement New feature or request labels Feb 2, 2024
@rustatian rustatian self-assigned this Feb 2, 2024
Copy link

coderabbitai bot commented Feb 2, 2024

Walkthrough

This update introduces a series of enhancements and bug fixes across the project. Key changes include improved error handling in Go code, the addition of a new test configuration for addressing a specific bug scenario, and updates to test cases to align with new configurations and address specific bugs. The changes aim to refine the project's robustness, particularly in error handling and testing, ensuring more accurate responses and behaviors under error conditions.

Changes

Files Change Summary
.gitignore Updated to exclude **/tests/test_certs/**.
handler/handler.go Refactored handleError for better error handling.
tests/configs/.rr-bug1843.yaml New file for server application configuration.
tests/handler_test.go Updated server address in TestHandler_Multipart_PATCH.
tests/http_plugin3_test.go, tests/http_plugin4_test.go Version updates, improved logic, and new test functions.
tests/php_test_files/bug1843.php Added PHP script for bug #1843 scenario.
.github/workflows/linux.yml PHP version update and directory creation step added.

Assessment against linked issues

Objective Addressed Explanation
Investigate and modify response status from 200 to 500 when PHP fails before new \Spiral\RoadRunner\Http\PSR7Worker() [#1843]
Ensure response status reflects failure state accurately, particularly for early exceptions in PHP script execution [#1843]
Provide a solution for setting HTTP response to 500 for errors occurring prior to PSR7 worker initialization in debug mode [#1843]

Related issues

  • roadrunner-server/roadrunner#1843: This issue is directly addressed by the changes in this PR, particularly through the new test case and configuration file aimed at reproducing and fixing the described bug scenario.

Poem

In the code's vast meadow, under the byte-sized sun,
A rabbit hopped, fixing bugs, having fun.
With each leap and bound, errors fell away,
"To better code," it cheered, "Hip, hip, hooray!" 🎉🐰

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.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3553c8b and 9335f13.
Files ignored due to path filters (8)
  • go.work.sum is excluded by: !**/*.sum
  • tests/go.mod is excluded by: !**/*.mod
  • tests/go.sum is excluded by: !**/*.sum
  • tests/test-certs/localhost+2-client-key.pem is excluded by: !**/*.pem
  • tests/test-certs/localhost+2-client.pem is excluded by: !**/*.pem
  • tests/test-certs/localhost+2-key.pem is excluded by: !**/*.pem
  • tests/test-certs/localhost+2.pem is excluded by: !**/*.pem
  • tests/test-certs/rootCA.pem is excluded by: !**/*.pem
Files selected for processing (7)
  • .gitignore (1 hunks)
  • handler/handler.go (1 hunks)
  • tests/configs/.rr-bug1843.yaml (1 hunks)
  • tests/handler_test.go (1 hunks)
  • tests/http_plugin3_test.go (2 hunks)
  • tests/http_plugin4_test.go (1 hunks)
  • tests/php_test_files/bug1843.php (1 hunks)
Additional comments: 8
tests/php_test_files/bug1843.php (1)
  • 1-2: The PHP script immediately throws an exception, which is intended for testing the server's error handling before the PSR7 worker is initialized. This approach is effective for simulating early script failures.
.gitignore (1)
  • 19-19: Adding **/tests/test_certs/** to .gitignore is a good practice to prevent test certificates from being tracked in version control, enhancing security.
tests/configs/.rr-bug1843.yaml (1)
  • 1-20: The configuration file is correctly set up to replicate the issue described in #1843, with appropriate server and HTTP settings for testing. This ensures the test environment is isolated and controlled.
tests/http_plugin4_test.go (1)
  • 96-178: The test function TestBug1843 is well-structured, making an HTTP request to trigger the error condition and asserting the expected 500 status code and error message. This effectively validates the fix for the reported issue.
handler/handler.go (1)
  • 214-225: Refactoring handleError to write an internal server error and set a special header if there are no free workers is a good improvement. Including the error message in the response when in debug mode is helpful for debugging.
tests/http_plugin3_test.go (2)
  • 505-505: Updating the version in the config.Plugin struct to "2023.3.1" aligns with the project's versioning scheme and ensures the test uses the correct configuration.
  • 611-617: Adding a delay before reading the directory contents and using assert.NotContains to check for file names is a more robust way to ensure temporary files are cleaned up after multipart form tests.
tests/handler_test.go (1)
  • 1463-1463: The server address in TestHandler_Multipart_PATCH was updated to :34432. Ensure this port is not used elsewhere in the tests or application to avoid conflicts.
Verification successful

The search for the usage of port 34432 within the codebase has returned only one occurrence, which is in the file tests/handler_test.go as specified in the review comment. This indicates that the port 34432 is not used elsewhere in the tests or application, thus avoiding potential conflicts.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the usage of port 34432 to ensure no conflicts.
rg ":34432"

Length of output: 117

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9335f13 and b332b1f.
Files ignored due to path filters (3)
  • go.work.sum is excluded by: !**/*.sum
  • tests/go.mod is excluded by: !**/*.mod
  • tests/go.sum is excluded by: !**/*.sum
Files selected for processing (2)
  • .github/workflows/linux.yml (2 hunks)
  • tests/http_plugin4_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/http_plugin4_test.go
Additional comments: 2
.github/workflows/linux.yml (2)
  • 20-20: PHP version updated to 8.3 in the CI pipeline. This change ensures compatibility with the latest PHP version.
  • 80-80: Added a step to create a test-certs directory and populate it with SSL certificates. This is essential for HTTPS tests, ensuring the CI environment is correctly set up for security testing.

@rustatian rustatian merged commit e58db29 into master Feb 3, 2024
6 checks passed
@rustatian rustatian deleted the fix/not-correct-error-code branch February 3, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
1 participant