Write full LUA call stack in log on critical error

Things that already exist in the current mod API
Post Reply
Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Write full LUA call stack in log on critical error

Post by Dark »

What the title says. Right now there is only little window with point of error, nothing else is provided.

It is frustrating to have refined code, with high amount of different small specialized methods only to find that such code is very hard to debug.
In such code point of original error has little meaning without knowledge of where it was originally called.

Crude pile of code in single method is actually a lot easier to debug.

I'll probable end up wrapping every event/data.lue in the xpcall for now, but at least pcall did not catch engine generated error on "die()" of a destroyed entity.

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Write full LUA call stack in log on critical error

Post by FreeER »

Dark wrote:In such code point of original error has little meaning without knowledge of where it was originally called.
If it's your code you can always do some error checking with if statements and use error("error message", 2) to 'throw' an error indicating that the caller of the function caused the problem. That can help, and of course pcall can be used to 'catch' those thrown errors :) see PIL Error Messages and Tracebacks (8.3-8.5 are about errors/exceptions)

But yeah...call stacks could be helpful at times :)

Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: Write full LUA call stack in log on critical error

Post by Rahjital »

I did some modding on Teleglitch (which actually uses Lua for it's game logic and doesn't even have official mod support) and the call stack written on an error was an extremely important tool. There's only so much predicting you can do. :)

Dark
Long Handed Inserter
Long Handed Inserter
Posts: 83
Joined: Wed May 07, 2014 12:45 pm
Contact:

Re: Write full LUA call stack in log on critical error

Post by Dark »

I think error() has it use if you expect an error and know what parameter/condition can cause it, but most of the time you can do little for an unexpected error.
You'll need to place an error() call in method of interest (along with xpcall to catch and print stack trace) then reproduce the error and only then analyze and fix it.
I'll do take a note of throwing error() next time, thanks :)

Post Reply

Return to “Already exists”