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

Tracebacks should include values of local variables #626

Open
aidanholm opened this issue Dec 9, 2017 · 1 comment
Open

Tracebacks should include values of local variables #626

aidanholm opened this issue Dec 9, 2017 · 1 comment

Comments

@aidanholm
Copy link
Member

  • possible privacy concern if URIs/bookmark/history details are included in tracebacks
    • it's difficult to detect which variables this applies to from a generic traceback()
  • difficult to display some variables
    • functions (but these won't usually be relevant)
    • tables need to be summarized in some fashion
@taobert
Copy link
Contributor

taobert commented Feb 7, 2021

https://github.com/ignacio/StackTracePlus may be relevant.
I've not used it, but it seems to support local variables, including tables.
It doesn't print function source, (which appears to be a non-trivial exercise).
Implementation seems to be as easy as:

local STP = require "StackTracePlus"
debug.traceback = STP.stacktrace

With respect to privacy concerns,
i think that guessing which fields are sensitive would be impossible to get right,
and would only lead to Luakit devs being blamed when someone (inevitably) posts that data.
I think, rather, that it'd be better to leave the fancier stack trace off by default,
and allow it to be enabled by users when/if they need to collect that data,
and that there should be warnings (in the docs, setting description, console output, etc)
that data may be leaked if a stack trace is generated,
and extra warnings to read, understand and redact any stack traces posted.

Edit (at 20210321):
So, the two-line implementation above doesn't (seem to) work with luajit.
Based on a StackTracePlus pull request, adding the following to the top of rc.lua:

if not package.loaded.StackTracePlus then
    local STP = require 'StackTracePlus'
    debug.traceback = STP.stacktrace
    assert(                          --rethrows error
        xpcall(                      --calls main function
            debug.getinfo( 1 ).func, --retrieves main function from call stack
            STP.stacktrace, ... ))   --passes through all arguments (may not work with 5.1, should work with LuaJIT)
    return  --terminate, so control flow won't move on to running
            --the rest of the main function again (we already ran that)
end

changes this stack trace:

[    1.742987] E [core/common/lualib]: Lua error: assertion failed!
                 Traceback:
                 (1) [C]                                                     in function assert
                 (2) /home/tao/.config/luakit/plugins/tabhistory/init.lua:61 in function _attach_signals_to_notebook
                 (3) /home/tao/.config/luakit/plugins/tabhistory/init.lua:97 in function sigfunc
                 (4) /usr/local/share/luakit/lib/lousy/signal.lua:84 in function emit_signal
                 (5) /usr/local/share/luakit/lib/window.lua:756 in function new
                 (6) /usr/local/share/luakit/lib/session.lua:127 in function restore_file
                 (7) /usr/local/share/luakit/lib/session.lua:161 in function restore
                 (8) /home/tao/.config/luakit/rc.lua:231 in main chunk

to:

[    1.534240] E [core/common/lualib]: Lua error: /home/tao/.config/luakit/plugins/tabhistory/init.lua:61: assertion failed!
                 Stack Traceback
                 ===============
                 (1) global C function 'assert'
                 (2) Lua upvalue '_attach_signals_to_notebook' at file '/home/tao/.config/luakit/plugins/tabhistory/init.lua:61'
                        Local variables:
                 (3) Lua local 'sigfunc' at file '/home/tao/.config/luakit/plugins/tabhistory/init.lua:97'
                        Local variables:
                         w = table: 0x42003c10  {emit_signal:function: 0x4038aca0, ibar:table: 0x410dc6b0, tablist:table: 0x41ac6e70 (more...)}
                 (4) Lua field 'emit_signal' at file '/usr/local/share/luakit/lib/lousy/signal.lua:84'
                        Local variables:
                         object = table: 0x41e69698  {methods:table: 0x4038abe0, emit_signal:function: 0x4037b930, build:function: 0x40390500 (more...)}
                         signame = string: "init"
                         d = table: 0x41e5c540  {signals:table: 0x4037e750, module:true}
                         sigfuncs = table: 0x41455138  {1:function: 0x408dbb30, 2:function: 0x402a34a0, 3:function: 0x41286828 (more...)}
                         (for generator) = C function: 0x41e52ea0
                         (for state) = table: 0x41455138  {1:function: 0x408dbb30, 2:function: 0x402a34a0, 3:function: 0x41286828 (more...)}
                         (for control) = number: 9
                         _ = number: 9
                         sigfunc = Lua function '(anonymous)' (defined at line 92 of chunk /home/tao/.config/luakit/plugins/tabhistory/init.lua)
                         ret = nil
                         (*temporary) = table: 0x401c7060  {}
                 (5) Lua field 'new' at file '/usr/local/share/luakit/lib/window.lua:756'
                        Local variables:
                         args = table: 0x40c08428  {1:luakit://newtab/}
                         w = table: 0x42003c10  {emit_signal:function: 0x4038aca0, ibar:table: 0x410dc6b0, tablist:table: 0x41ac6e70 (more...)}
                 (6) Lua upvalue 'restore_file' at file '/usr/local/share/luakit/lib/session.lua:127'
                        Local variables:
                         file = string: "/home/tao/.config/luakit/session"
                         delete = nil
                         ok = boolean: true
                         wins = table: 0x41ccbd28  {1:table: 0x41c99488}
                         state = table: 0x4088d0f8  {}
                         w = nil
                         (for generator) = C function: 0x41e52ea0
                         (for state) = table: 0x41ccbd28  {1:table: 0x41c99488}
                         (for control) = number: 1
                         _ = number: 1
                         win = table: 0x41c99488  {tab_groups:table: 0x40d09228, closed:table: 0x412819a8, open:table: 0x402ab268 (more...)}
                         (for generator) = C function: 0x41e52ea0
                         (for state) = table: 0x402ab268  {8:table: 0x4012c080, 2:table: 0x40575eb0, 5:table: 0x4079afe0, 3:table: 0x402d4598 (more...)}
                         (for control) = number: 1
                         _ = number: 1
                         item = table: 0x41d36420  {ti:1, current:false, uri:https://github.com/luakit/luakit/issues/626, session_state:
                 Traceback:
                 (1) [C]                                in function assert
                 (2) /home/tao/.config/luakit/rc.lua:10 in main chunk

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

No branches or pull requests

2 participants