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 #1419: проверка типов перечислений при передаче параметров и присваивании #1421

Merged
merged 5 commits into from
Jul 4, 2024

Conversation

Mr-Rm
Copy link
Collaborator

@Mr-Rm Mr-Rm commented Jun 21, 2024

Summary by CodeRabbit

  • New Features

    • Added a default message for "Type mismatch" in the TypeConversionException constructor.
  • Bug Fixes

    • Improved cursor positioning logic and enhanced error handling for color setting methods in console contexts.
  • Improvements

    • Enhanced type checking logic within value conversion to ensure compatibility before casting.

Copy link

coderabbitai bot commented Jun 21, 2024

Walkthrough

The latest changes introduce a range of updates focusing on enhancing error handling, type conversion, and logic in various components. Key changes include a new constructor for TypeConversionException to provide a default message, adjustments to cursor positioning and color handling logic in the ConsoleContext, and additional type-checking logic in ContextValuesMarshaller.

Changes

File Change Summary
src/OneScript.Core/Exceptions/TypeConversionException.cs Added a constructor with a default message for "Type mismatch."
src/OneScript.StandardLibrary/Text/ConsoleContext.cs Adjusted X and Y position setters for cursor placement; added error handling for color conversion; refined the return value of BackgroundColor.
src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs Introduced additional type-checking logic in the ConvertValueType method for IObjectWrapper compatibility.

Poem

In the land of code so wise,
A mismatch for types no more surprise,
In console's dance, colors align,
Cursor's steps, precision fine.
With checks so keen, and logic sharp,
Error's grip, we've unplugged the harp.
A rabbit's joy in each byte's form,
Coding realms, now transformed. 🌟🐇


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 Configration 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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0b0a505 and b7fbdfe.

Files selected for processing (3)
  • src/OneScript.Core/Exceptions/TypeConversionException.cs (1 hunks)
  • src/OneScript.StandardLibrary/Text/ConsoleContext.cs (5 hunks)
  • src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs (1 hunks)
Additional comments not posted (2)
src/OneScript.StandardLibrary/Text/ConsoleContext.cs (1)

43-43: Improved cursor positioning logic.

The modification ensures that the cursor position does not exceed the console's window width. This is a good preventive measure against runtime errors.

src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs (1)

135-145: Enhanced type safety in type conversion.

The added checks ensure that the type of the underlying object matches the expected type before casting, which is crucial for preventing runtime type errors. This is a solid enhancement for robustness.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7fbdfe and 459aebe.

Files selected for processing (1)
  • src/OneScript.Core/Exceptions/TypeConversionException.cs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/OneScript.Core/Exceptions/TypeConversionException.cs

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 459aebe and 1f3894e.

Files selected for processing (1)
  • src/OneScript.StandardLibrary/Text/ConsoleContext.cs (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/OneScript.StandardLibrary/Text/ConsoleContext.cs

@Mr-Rm
Copy link
Collaborator Author

Mr-Rm commented Jun 21, 2024

В Консоли ЦветТекста и ЦветФона получаются двумя разными способами: через ConsoleColorEnum.Instance и GlobalsHelper.GetEnum<ConsoleColorEnum> соответственно.
К.м.к., поменять бы оба.

@EvilBeaver
Copy link
Owner

соответственно. К.м.к., поменять бы оба.

Согласен. На что именно?

@Mr-Rm
Copy link
Collaborator Author

Mr-Rm commented Jun 21, 2024

Что-то вроде такого

[EnumerationType(ЦветКонсоли", "ConsoleColor")]
public enum ConsoleColorEnum
{
   [EnumValue("Черный", "Black")]
   Black = System.ConsoleColor.Black,
   [EnumValue("ТемноСиний", "DarkBlue")]
   DarkBlue = ConsoleColor.DarkBlue,
// ...
}

public static IValue ToBSLValue(this System.ConsoleColor color)
{
// ...
}

И подобное для других перечислений.

@Mr-Rm
Copy link
Collaborator Author

Mr-Rm commented Jun 24, 2024

@EvilBeaver for review:
Mr-Rm@e79ef85

@maximkin7
Copy link
Contributor

maximkin7 commented Jun 24, 2024 via email

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1f3894e and f04ef24.

Files selected for processing (1)
  • src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/ScriptEngine/Machine/Contexts/ContextValuesMarshaller.cs

@Mr-Rm
Copy link
Collaborator Author

Mr-Rm commented Jul 4, 2024

Заявленная ошибка исправлена, предлагаю влить в v2.

Переделка перечислений, и чтоб ничего не сломалось - долгая процедура. Сейчас в движке есть минимум пять вариантов работы с ними. Да и особенности C# накладываются.

@EvilBeaver EvilBeaver merged commit 9ce002f into EvilBeaver:develop Jul 4, 2024
1 of 2 checks passed
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.

4 participants