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

Wrap panic errors #7

Merged
merged 3 commits into from
Jul 24, 2024
Merged

Wrap panic errors #7

merged 3 commits into from
Jul 24, 2024

Conversation

bdeneux
Copy link

@bdeneux bdeneux commented Jul 24, 2024

Add a wrapper typed error over the panic error to facilitate error catching and comparison, enabling the return of more appropriate errors on the logic module side.

This improvement will be used in the logic module to correctly catch the ErrMaxVariables error in order to return a more appropriate gRPC error (LimitExceeded). Available in axone-protocol/axoned#703 (not implemented yet)

Copy link

coderabbitai bot commented Jul 24, 2024

Walkthrough

The recent changes enhance the virtual machine's error handling capabilities by introducing a new function, do_not_call_wrapped, which triggers panics with improved error reporting. A structured PanicError type now wraps original error messages, providing better context during panic scenarios. Additionally, the visibility of the error variable in variable.go has been improved, allowing for easier access in other parts of the codebase. Overall, these modifications streamline error management and increase the robustness of the VM's functionality.

Changes

File Change Summary
engine/builtin_test.go Introduced do_not_call_wrapped function with panic behavior; updated test cases to use PanicError for error handling.
engine/promise.go Enhanced panicError function with type switching for error handling; added PanicError struct to improve error encapsulation.
engine/variable.go Renamed errMaxVariables to ErrMaxVariables for better visibility; updated usage in NewVariable function.

Sequence Diagram(s)

sequenceDiagram
    participant VM
    participant FunctionRegistry
    participant ErrorHandler

    VM->>FunctionRegistry: Register do_not_call_wrapped
    VM->>VM: Call do_not_call_wrapped
    VM-->>ErrorHandler: Trigger panic
    ErrorHandler->>ErrorHandler: Wrap original error in PanicError
    ErrorHandler->>VM: Return PanicError
Loading

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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

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

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.

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #7      +/-   ##
==========================================
- Coverage   98.34%   98.31%   -0.03%     
==========================================
  Files          23       23              
  Lines        6513     6519       +6     
==========================================
+ Hits         6405     6409       +4     
- Misses         79       81       +2     
  Partials       29       29              
Files Coverage Δ
engine/variable.go 97.14% <100.00%> (ø)
engine/promise.go 97.50% <71.42%> (-2.50%) ⬇️

@bdeneux bdeneux marked this pull request as ready for review July 24, 2024 09:22
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b5a8728 and 7d0eab8.

Files selected for processing (3)
  • engine/builtin_test.go (2 hunks)
  • engine/promise.go (2 hunks)
  • engine/variable.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • engine/variable.go
Additional context used
GitHub Check: codecov/patch
engine/promise.go

[warning] 178-179: engine/promise.go#L178-L179
Added lines #L178 - L179 were not covered by tests

Additional comments not posted (4)
engine/promise.go (2)

173-176: LGTM!

The introduction of the PanicError struct improves error tracking and management by wrapping original error messages.


132-137: LGTM! Verify the usage of PanicError throughout the codebase.

The changes to the panicError function improve error handling by distinguishing between error types and other types, and wrapping them in a PanicError type.

However, ensure that the new PanicError type is used correctly throughout the codebase.

Verification successful

Verified: The PanicError type is used correctly throughout the codebase.

The PanicError type is consistently used in engine/promise.go for error handling and is also tested in engine/builtin_test.go.

  • engine/promise.go: Definition and usage of PanicError.
  • engine/builtin_test.go: Test cases involving PanicError.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `PanicError` type throughout the codebase.

# Test: Search for the usage of `PanicError`. Expect: Correct usage in all relevant places.
rg --type go 'PanicError'

Length of output: 699

engine/builtin_test.go (2)

36-38: LGTM! The new function registration is consistent with improved error handling.

The do_not_call_wrapped function panics with a wrapped error message, which aligns with the goal of enhancing error reporting.


66-68: LGTM! The updated error handling in test cases is consistent with improved error reporting.

The use of PanicError in test cases enhances the structure and clarity of error handling. The new test case for do_not_call_wrapped ensures proper testing of the new function.

engine/promise.go Show resolved Hide resolved
@bdeneux bdeneux requested review from ccamel and amimart July 24, 2024 09:28
Copy link
Member

@amimart amimart left a comment

Choose a reason for hiding this comment

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

Yep that makes sense 👍

Copy link
Member

@ccamel ccamel left a comment

Choose a reason for hiding this comment

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

Lgtm

@bdeneux bdeneux merged commit ea00e9b into main Jul 24, 2024
1 of 2 checks passed
@bdeneux bdeneux deleted the feat/impove-panic-error branch July 24, 2024 09:52
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.

3 participants