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

Inconsistent exception messages #525

Open
CryoViking opened this issue Feb 14, 2024 · 0 comments
Open

Inconsistent exception messages #525

CryoViking opened this issue Feb 14, 2024 · 0 comments

Comments

@CryoViking
Copy link

CryoViking commented Feb 14, 2024

Preface

I while ago I opened an issue about not getting an expected error message back from the lua instance and closed it because it happened to work properly for some reason when I went to try again. I've now ran into a problem where most of my error messages are matching up to what I would expect, however a particular type of error seems to be breaking the normal expected output.

Working Example:

Lua m_lua = new Lua();
string lua_script = @"
    local function add(a, b)
      return a + b
    end

    local function mult(a, b)
      return a * b
    end

    local result = add(5, "something")
    print(result)
    ";
try {
  m_lua.DoString(script);
}
catch(Exception ex) {
  Console.WriteLine(ex.Message);
}

Expected (lua interpreter)

Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
> function add(a,b)
>> return a+b
>> end
> result = add(10, "something")
stdin:2: attempt to add a 'number' with a 'string'
stack traceback:
        [C]: in metamethod 'add'
        stdin:2: in function 'add'
        stdin:1: in main chunk
        [C]: in ?

Result (from c#)

[string "chunk"]:2: attempt to add a 'number' with a 'string'
stack traceback:
	[C]: in metamethod 'add'
	[string "chunk"]:2: in local 'add'
	[string "chunk"]:5: in main chunk

As you can see, it lines up fairly well.

Failing Example:

Now the case that I have found that does not work as expected, is when I do the following:

Lua m_lua = new Lua();
string lua_script = @"
    some_function_that_does_not_exist()
    ";
try {
  m_lua.DoString(script);
}
catch(Exception ex) {
  Console.WriteLine(ex.Message);
}

Expected (lua interpreter)

Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
> some_function_that_does_not_exist()
stdin:1: attempt to call a nil value (global 'some_function_that_does_not_exist')
stack traceback:
        stdin:1: in main chunk
        [C]: in ?

Result (from c#)

[string "chunk"]:12: C stack overflow
stack traceback:
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        ...     (skipping 177 levels)
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:12: in metamethod 'index'
        [string "chunk"]:2: in main chunk

I'm wondering if there is something I am missing in this very simple example. Or if this is just one of those edge cases that I've stumbled into.

Let me know if I need to provide more information in regards to this problem. It's not a major issue at the moment and a workaround I might implement at some point if I don't get a resolution here will be to regex for the pattern and override the message.

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

No branches or pull requests

1 participant