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: re-land papyrus error handling fix #2329

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

Conversation

Pospelove
Copy link
Contributor

@Pospelove Pospelove commented Feb 10, 2025

Reverts #2314


Important

Reintroduces error handling improvements in Papyrus VM by replacing exceptions with logging and default returns, updating related tests.

  • Error Handling:
    • Replaced exceptions with spdlog logging in ActivePexInstance.cpp, VarValue.cpp, and VirtualMachine.cpp.
    • Functions like ExecuteOpCode, GetVariableValueByName, and CallMethod now log errors and return default values instead of throwing exceptions.
  • Function Modifications:
    • Added noexcept to ExecuteAll and ExecuteOpCode in ActivePexInstance.h.
    • Removed ExceptionHandler from VirtualMachine.h.
  • Test Updates:
    • Removed exception-based tests in VarValueTest.cpp for identifier and nonexistent types.
    • Updated tests to check for default return values instead of exceptions.

This description was created by Ellipsis for cd71610. It will automatically update as commits are pushed.

@Pospelove Pospelove requested a review from nic11 February 10, 2025 16:54
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to cd71610 in 50 seconds

More details
  • Looked at 953 lines of code in 7 files
  • Skipped 0 files when reviewing.
  • Skipped posting 11 drafted comments based on config settings.
1. unit/VarValueTest.cpp:9
  • Draft comment:
    Good tests for boolean comparisons. The use of REQUIRE with casting to bool is clear.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. unit/VarValueTest.cpp:19
  • Draft comment:
    Test for the assignment operator on owning objects is clear. Consider covering deep copy edge cases further, though current test verifies that stringHolder is deep-copied.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
3. unit/VarValueTest.cpp:44
  • Draft comment:
    Equality operator tests for objects are straightforward. Test verifies that equal objects (by value) compare equal and different values compare unequal.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
4. unit/VarValueTest.cpp:82
  • Draft comment:
    Tests for wrong types and casting functions look adequate. Ensure that numeric conversions (e.g. from string to int or float) behave as expected.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
5. unit/VarValueTest.cpp:97
  • Draft comment:
    The strcat implicit cast test is concise and confirms the functionality provided by OpcodesImplementation::StrCat.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
6. unit/VarValueTest.cpp:105
  • Draft comment:
    Mixed arithmetics test checks various math operations and matches string output. The use of string streams validates the print representation.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
7. unit/VarValueTest.cpp:124
  • Draft comment:
    Cast to string tests cover both numeric and array cases. The expected output of '[None, None]' for an array of None is verified.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
8. unit/VarValueTest.cpp:136
  • Draft comment:
    Final operator== test is clear in verifying string equality and differences.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
9. papyrus-vm/src/papyrus-vm-lib/VarValue.cpp:221
  • Draft comment:
    In the ToDouble function, the kType_Float case casts the value to int32_t before conversion, losing the fractional part. Use the float value directly (e.g. v.data.f) instead.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
10. papyrus-vm/src/papyrus-vm-lib/VarValue.cpp:327
  • Draft comment:
    The operator/ for integers returns 1 when division by zero occurs, which can mask errors. Consider explicitly handling division by zero instead of defaulting to 1.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
11. papyrus-vm/src/papyrus-vm-lib/VarValue.cpp:629
  • Draft comment:
    Using a precision value of 9000 in snprintf for CastToString in the float case is excessively high and may cause formatting issues. Consider using a more typical precision value.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_BoWUx2EhFMmqMTiy


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@nic11
Copy link
Collaborator

nic11 commented Feb 10, 2025

I would still first implement execution budget

spdlog::error("ActivePexInstance::GetVariableValueByName - "
"GetVariableByName errored with '{}'",
e.what());
noneVar = VarValue::None();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is better to declare and initialize this before try .

} catch (...) {
spdlog::critical("ActivePexInstance::GetVariableValueByName - "
"GetVariableByName errored with unknown error");
noneVar = VarValue::None();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better initialize it once somewhere before try.

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