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

[VM] rename vm catchable and uncatchable exceptions #3538

Closed
wants to merge 18 commits into from

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Oct 17, 2024

Description

This pr tries to improve the VM exception type and inforamtion, making it easier to understand the VM exception.

Fixes # #3536

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 17, 2024

@roman-khimov @shargon please take a look, this is what i want to do with the exception currently. It just make it clear what the exception are and enfoce an exception message. If you think it is good to go, i will finish this pr. I think nothing will be influenced.

@Jim8y
Copy link
Contributor Author

Jim8y commented Oct 17, 2024

Well, need to udpate UT still~~~ UTs are affected since exception type are different

src/Neo.VM/ExecutionEngine.cs Outdated Show resolved Hide resolved
Comment on lines 20 to 21
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to avoid this, this error will be throw during runtime, is not a warning for us

Copy link
Member

Choose a reason for hiding this comment

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

yes remove this, and add a default message when null.

Comment on lines 20 to 21
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Member

Choose a reason for hiding this comment

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

Add default message on null.

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

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

LGTM, @Jim8y

{
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Copy link
Contributor

@nan01ab nan01ab Oct 23, 2024

Choose a reason for hiding this comment

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

Throw another Exception when constructing an Exception is not good practice.

Comment on lines 20 to 21
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Copy link
Member

Choose a reason for hiding this comment

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

yes remove this, and add a default message when null.

Comment on lines 20 to 21
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Copy link
Member

Choose a reason for hiding this comment

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

Add default message on null.

@shargon
Copy link
Member

shargon commented Nov 7, 2024

@Jim8y please take a look that there are no any more left, and the most important, no changes in catchable exceptions

@cschuchardt88 cschuchardt88 self-requested a review November 12, 2024 23:06
cschuchardt88
cschuchardt88 previously approved these changes Nov 12, 2024

namespace Neo.VM.Exceptions
{
public interface IVMException
Copy link
Member

Choose a reason for hiding this comment

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

Making a requirement of for this is irrelevant, just use Exception.

Doing this will make the message required for example:

public class BadScriptException(string message) : Exception(message) { }

{
}
}
public class VMCatchableException(string message) : Exception($"{message}"), IVMException;
Copy link
Member

@cschuchardt88 cschuchardt88 Nov 29, 2024

Choose a reason for hiding this comment

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

Remove the interface, its unneeded. also the $"" is unneeded too.

/// is not catchable by the VM, and will directly cause the VM execution to fault.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public class VmUncatchableException(string message) : Exception(message), IVMException
Copy link
Member

Choose a reason for hiding this comment

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

remove the interface

@Jim8y
Copy link
Contributor Author

Jim8y commented Dec 17, 2024

Its hard to implement what i planed without change the exception name, maybe just keep it as it is.

@Jim8y Jim8y closed this Dec 17, 2024
@Jim8y Jim8y deleted the vm-type branch December 17, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants