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

Error string in Exception Handler is nil when an exception is thrown from a conditional statement #3080

Open
ZZ-Cat opened this issue Jun 5, 2024 · 1 comment
Labels

Comments

@ZZ-Cat
Copy link

ZZ-Cat commented Jun 5, 2024

Describe the bug

When a conditional statement is used inside the Try block to determine whether-or-not an exception is thrown, and that condition causes an exception to be thrown, the resulting string from the caught exception is (nil) in the Exception Handler.

To Reproduce

  1. Enter the following snippet into a fresh E2 file (overwriting the boilerplate code in the process)...
@name exception_handling_test
@strict

if (first())
{
    # Set Throw_an_exception to any value other than zero to trigger an exception, right off the bat.
    let Throw_an_exception = 1

    try
    {
        if (Throw_an_exception != 0)
        {
            error("An exception was throw, right off the bat.")
        }
    }
    catch(Exception:string)
    {
        # The Exception string is not actually printed, because it technically contains nothing.
        print("Exception caught:")
        print(Exception)
        #]#

        #[You MAY comment out the print statements above, to test the error ping here.
        # NOTE: The E2 will shut down, and an obscure error notification regarding string handling will show instead.
        print("Exception caught: " + Exception)
        #]#
    }
}
  1. Spawn the E2 chip somewhere.
  2. Chat print will simply read Exception caught: with no text present where An exception was thrown, right off the bat. should be.

Alternatively, you can combine the two print() statements to look like print("Exception caught: " + Exception), and the E2 will shut down with an obscure error (see attached screenshot).

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots

Screenshot from 2024-06-05 20-07-59
This error comes up when Exception is combined with any string constant.

@Vurv78
Copy link
Contributor

Vurv78 commented Aug 6, 2024

This is just a guess since I can't debug it, but maybe this is at fault:

https://github.com/wiremod/wire/blob/master/lua/entities/gmod_wire_expression2/base/compiler.lua

						state.Scope[err_var.value] = (type(msg) == "string") and msg or ""

err_var.value really shouldn't be there at runtime (bind to a variable in case err_var is changed). although you'd think that would cause an error from setting a nil index..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants