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

В конструктор ИнформацияОбОшибке, добавлен параметр "Причина" для возможности указания причины текущей ошибки #1494

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sfaqer
Copy link
Contributor

@sfaqer sfaqer commented Jan 18, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced exception handling with improved context tracking
    • Added ability to include cause information for exceptions
  • Bug Fixes

    • Improved exception information preservation and propagation
  • Tests

    • Added new test case for verifying error information with cause

The changes focus on strengthening the error handling mechanism by allowing more detailed exception tracking and context preservation across the application's exception management system.

Copy link

coderabbitai bot commented Jan 18, 2025

Walkthrough

This pull request enhances exception handling capabilities across multiple classes in the ScriptEngine. The changes focus on improving the ability to track and propagate nested exceptions by introducing a new cause parameter in exception-related constructors and methods. The modifications span several key classes including ExceptionInfoContext, ExceptionInfoFactory, MachineInstance, and ParametrizedRuntimeException, allowing for more detailed exception context preservation and reporting.

Changes

File Changes
src/ScriptEngine/Machine/Contexts/ExceptionInfoContext.cs - Updated constructor to accept ExceptionInfoContext cause
- Changed ActualException() method visibility from private to public
- Modified Create() method to include optional cause parameter
src/ScriptEngine/Machine/ExceptionInfoFactory.cs - Updated Raise() method to pass inner exception when creating ParametrizedRuntimeException
src/ScriptEngine/Machine/MachineInstance.cs - Modified RaiseException() to include InnerException when throwing ParametrizedRuntimeException
src/ScriptEngine/Machine/ParametrizedRuntimeException.cs - Added optional cause parameter to constructor
- Introduced new Cause property of type IValue
tests/global-funcs.os - Added new test procedure Тест_ДолженПроверитьИнформацияОбОшибкеСПричиной to validate exception cause handling

Sequence Diagram

sequenceDiagram
    participant Client
    participant ExceptionInfoContext
    participant ParametrizedRuntimeException
    
    Client->>ExceptionInfoContext: Create(message, parameters, cause)
    ExceptionInfoContext-->>Client: Return ExceptionInfoContext
    Client->>ParametrizedRuntimeException: Raise with ExceptionInfoContext
    ParametrizedRuntimeException-->>Client: Exception with cause preserved
Loading

Possibly related PRs

Suggested reviewers

  • EvilBeaver

Poem

🐰 In the realm of code, where errors dance,
A rabbit hops with exception's advance
Nested contexts, causes clear and bright
Debugging becomes a joyful delight!
Error tracking, now with grace and might 🚀


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.

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: 0

🧹 Nitpick comments (2)
src/ScriptEngine/Machine/Contexts/ExceptionInfoContext.cs (1)

198-208: Enhance XML documentation for the 'Create' method.

The XML comments for the Create method are incomplete. Providing detailed summaries and parameter descriptions improves code maintainability and developer understanding.

Apply this diff to enhance the documentation:

 /// <summary>
-///
+/// Creates a new instance of ExceptionInfoContext with the ability to specify the cause of the exception.
 /// </summary>
+/// <param name="msg">String - Error message</param>
+/// <param name="parameter">Any - Additional information</param>
+/// <param name="cause">ExceptionInfoContext - The cause of the current exception</param>
 /// <returns>ExceptionInfoContext instance.</returns>
src/ScriptEngine/Machine/ParametrizedRuntimeException.cs (1)

9-9: Remove unnecessary using directive.

The using ScriptEngine.Machine.Contexts; directive is not used in this file. Removing it prevents clutter and adheres to clean code practices.

Apply this diff to remove the unused directive:

-using ScriptEngine.Machine.Contexts;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62c8464 and 380dd6b.

📒 Files selected for processing (5)
  • src/ScriptEngine/Machine/Contexts/ExceptionInfoContext.cs (4 hunks)
  • src/ScriptEngine/Machine/ExceptionInfoFactory.cs (1 hunks)
  • src/ScriptEngine/Machine/MachineInstance.cs (1 hunks)
  • src/ScriptEngine/Machine/ParametrizedRuntimeException.cs (1 hunks)
  • tests/global-funcs.os (2 hunks)
🔇 Additional comments (10)
src/ScriptEngine/Machine/Contexts/ExceptionInfoContext.cs (4)

36-40: Constructor enhancement looks good.

The addition of the cause parameter to the constructor allows for proper tracking of nested exceptions.


52-52: Assignment of 'Cause' property is appropriate.

Assigning pre.Cause to _innerException correctly maintains the exception chain.


Line range hint 56-65: Verify the necessity of making 'ActualException()' method public.

Changing ActualException() from private to public exposes internal exception details. Ensure this change is intentional and does not leak sensitive information or break encapsulation.


152-153: Null-check on 'exc.InnerException' is handled correctly.

The null-check prevents potential NullReferenceException when there is no inner exception.

src/ScriptEngine/Machine/ParametrizedRuntimeException.cs (2)

15-18: Constructor modification is appropriate.

Adding the optional cause parameter to the constructor allows exceptions to carry additional context.


22-22: 'Cause' property added correctly.

The Cause property aligns with the constructor parameter, enabling access to the exception's cause.

src/ScriptEngine/Machine/ExceptionInfoFactory.cs (1)

51-51: Update to 'Raise' method ensures proper exception propagation.

Passing excInfo.InnerException to the ParametrizedRuntimeException constructor allows for detailed exception context and proper chaining.

tests/global-funcs.os (2)

80-80: LGTM!

The new test case is properly registered in the test list.


892-934: LGTM! Well-structured test case for nested exception handling.

The test case thoroughly verifies:

  1. Original exception capture
  2. Creation of new error with cause
  3. Error description propagation
  4. Cause preservation
src/ScriptEngine/Machine/MachineInstance.cs (1)

1255-1259: LGTM! Proper implementation of nested exception support.

The modification correctly passes the inner exception when creating a ParametrizedRuntimeException, enabling proper exception chaining.

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.

1 participant