lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

debug.traceback(..., level) is not behaving how I'd expect or according to the documentation.

> An optional level number tells at which level to start the traceback (default is 1, the function calling traceback).

So if the level is 3, for example, I'd expect the traceback to start at the 3rd frame in the call stack.  But that's not the exhibited behavior.  Level affects the location prepended to string errors, but not the starting point of the traceback.

The use case of "level" is to show the source of an error higher in the stack than actual, usually in order to hide implementation details of a library.  So I believe the documentation reflects the useful and expected behavior.

To my surprise, traceback() used to match the documentation, but it was changed in 2015 in response to a post making the following argument:

> This makes it hard to transparently wrap error producing functions,
as the amount of wrapping you do will effect the usefulness of the traceback

I find the opposite to be so.  If you have some utility wrapping errors, this is precisely where you'd want to hide the uninteresting details of your wrapper by using level.