mikehend / luainterface

Automatically exported from code.google.com/p/luainterface
0 stars 0 forks source link

Error info should include the line number #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The previous 2.0 can provide chunk name and line number in error string
when a lua parsing error occurs, but not when an exception is thrown from
.NET code.

I looked through the code and found that in ThrowExceptionFromError(), it
only gets the chunk name and line number and adds them to the error string
for lua errors but not for .NET exceptions. I tried to modify it so that it
also extracts the chunk name and line number for the error when the error
is a .NET exception, and it works great. It helps a lot for me to find
where exactly the error occurs in lua source code.

In the 2.0.3 release, I saw the code which fetch the chunk name and line
number information is missing. Why? I think it is great to always have
those information.

Original issue reported on code.google.com by qingrui...@gmail.com on 6 May 2009 at 9:24

GoogleCodeExporter commented 9 years ago
Hmm, I'm not sure why it is missing to be honest. Care to submit a patch or 
paste 
your changes here and ill merge back in?

Original comment by capre...@gmail.com on 21 May 2009 at 5:07

GoogleCodeExporter commented 9 years ago
Sorry, just checked my code, it is not in ThrowExceptionFromError() but in
ObjectTranslator.throwError(). The old code is still there. The thing I added 
is to
also provide chunck name and line number for Exceptions raised from .NET side.

It's like this:
internal void throwError(IntPtr luaState,object e) 
{
            // If the argument is a mere string, we are free to add extra info to it
(as opposed to some private C# exception object or somesuch, which we just pass 
up)

            // We use this to remove anything pushed by luaL_where
            int oldTop = LuaDLL.lua_gettop(luaState);

            // Stack frame #1 is our C# wrapper, so not very interesting to the user
            // Stack frame #2 must be the lua code that called us, so that's what we
want to use
            LuaDLL.luaL_where(luaState, 1);
            object[] curlev = popValues(luaState, oldTop);
            // Debug.WriteLine(curlev);

            string errLocation = "";
            if (curlev.Length > 0)
                errLocation = curlev[0].ToString();

            if (e is string)
                e = errLocation + e;
            else if (e is Exception)
            {
                Exception ex = e as Exception;
                Exception luaex = new ApplicationException(errLocation + ex.Message, ex);
                e = luaex;
            }

    push(luaState,e);
    LuaDLL.lua_error(luaState);
}

Here the use of ApplicationException should be a bad idea. I just wrote it to 
make a
quick working build.

Original comment by qrl...@gmail.com on 21 May 2009 at 11:58

GoogleCodeExporter commented 9 years ago
Fixed in r14, please verify

Original comment by capre...@gmail.com on 16 Sep 2009 at 4:31