Skip to content

fix: do not try to call Error() on nil err#138

Merged
rustatian merged 1 commit into
masterfrom
fix/2125-no-free-workers-panic
Feb 12, 2025
Merged

fix: do not try to call Error() on nil err#138
rustatian merged 1 commit into
masterfrom
fix/2125-no-free-workers-panic

Conversation

@rustatian

@rustatian rustatian commented Feb 12, 2025

Copy link
Copy Markdown
Member

Reason for This PR

closes: roadrunner-server/roadrunner#2125

Description of Changes

  • Check if the unwrapped error is not nil before calling Error() on it.

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

  • Bug Fixes

    • Enhanced error handling to gracefully manage scenarios where no error is present, reducing the risk of unexpected behavior and ensuring a more stable experience for users.
  • Tests

    • Expanded the testing suite to cover multiple error scenarios, validating the robustness of the improved error management and further increasing overall reliability.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added the bug Something isn't working label Feb 12, 2025
@rustatian rustatian requested a review from wolfy-j February 12, 2025 13:36
@rustatian rustatian self-assigned this Feb 12, 2025
@coderabbitai

coderabbitai Bot commented Feb 12, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce a nil-check in the GetOriginalErr function, ensuring that if an error is nil, an empty string is returned rather than proceeding with further processing. Additionally, new helper functions and test cases have been added in the test file to simulate error chains and verify correct error handling for both non-nil errors (yielding specific error messages) and nil errors.

Changes

File Path Change Summary
proxy/proxy.go Added a conditional check in GetOriginalErr to return an empty string when the input error is nil.
proxy/proxy_test.go Added new error-generating functions (err, err2, err3, err4, err5) and two test cases (TestWrapDifferentError, TestWrapNilError) to verify different error handling scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant TC as Test Case
    participant E1 as err
    participant E2 as err2
    participant E3 as err3
    participant WE as wrapError
    participant GOE as GetOriginalErr

    %% Flow for non-nil error chain
    TC->>E1: Call err()
    E1->>E2: Call err2()
    E2->>E3: Call err3()
    E3-->>E2: Return error ("NoFreeWorkers")
    E2-->>E1: Return error ("NoFreeWorkers")
    E1-->>TC: Return error ("NoFreeWorkers")
    TC->>WE: Call wrapError(error)
    WE->>GOE: Pass error to GetOriginalErr
    GOE-->>WE: Return error message ("NoFreeWorkers")
    WE-->>TC: Return wrapped error

Loading
sequenceDiagram
    participant TC as Test Case
    participant E4 as err4
    participant E5 as err5
    participant WE as wrapError
    participant GOE as GetOriginalErr

    %% Flow for nil error chain
    TC->>E4: Call err4()
    E4->>E5: Call err5()
    E5-->>E4: Return nil
    E4-->>TC: Return nil
    TC->>WE: Call wrapError(nil)
    WE->>GOE: Pass nil to GetOriginalErr
    GOE-->>WE: Return empty string
    WE-->>TC: Return wrapped empty message

Loading

Poem

I'm a bunny, swift and spry,
Hopping on changes that catch my eye.
Nil checks here, errors cleared away,
Test cases bloom like buds in May.
With a twitch of my nose 🐰, I cheer this day!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a09504d and f7f4859.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • proxy/proxy.go (1 hunks)
  • proxy/proxy_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gRPC plugin (Go stable, PHP 8.4, OS ubuntu-latest)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
proxy/proxy.go (1)

351-353: LGTM! Proper nil check added.

The added nil check prevents calling Error() on a nil error and returns an empty string, which is consistent with the function's behavior when no error is found.

proxy/proxy_test.go (4)

18-28: LGTM! Well-structured error chain helpers.

The helper functions create a realistic error chain that's useful for testing error unwrapping behavior.


30-36: LGTM! Good nil error test helpers.

The helper functions properly set up a scenario where a nil error is wrapped, which is essential for testing the new nil check.


38-41: LGTM! Good baseline test for error wrapping.

The test verifies that error wrapping works correctly for non-nil errors, providing a good baseline for comparison.


43-46: LGTM! Essential test for nil error handling.

This test is crucial as it verifies the fix for the nil error case, ensuring that wrapping a nil error produces a proper error message instead of panicking.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@rustatian rustatian merged commit 84f9d42 into master Feb 12, 2025
@rustatian rustatian deleted the fix/2125-no-free-workers-panic branch February 12, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 BUG]: Panic is triggered when NoFreeWorkers

1 participant