clean up some cruft from error callstacks

akkartik
Nov 10, 2023, 4:43 PM
NLU6BXIRLLAEMZUKPWIL66WWDXB3RQVAPXPXPWO7KCR2YIIKEGFAC

Dependencies

  • [2] 6JKFAHNL remove a no-op regex munging on callstacks
  • [3] AVTNUQYR basic test-enabled framework
  • [4] IZGZEWFG switch to source editor on error
  • [*] 3QNOKBFM beginnings of a test harness
  • [*] CUFW4EJL reorganize app.lua and its comments

Change contents

  • replacement in app.lua at line 46
    [3.299][2.0:82]()
    Error_message = debug.traceback('Error: ' .. tostring(err), --[[stack frame]]2)
    [3.299]
    [3.403]
    local callstack = debug.traceback('', --[[stack frame]]2)
    Error_message = 'Error: ' .. tostring(err)..'\n'..clean_up_callstack(callstack)
  • edit in app.lua at line 60
    [3.709]
    [7.305]
    -- I tend to read code from files myself (say using love.filesystem calls)
    -- rather than offload that to load().
    -- Functions compiled in this manner have ugly filenames of the form [string "filename"]
    -- This function cleans out this cruft from error callstacks.
    function clean_up_callstack(callstack)
    local frames = {}
    print(callstack)
    for frame in string.gmatch(callstack, '[^\n]+\n*') do
    local line = frame:gsub('^%s*(.-)\n?$', '%1')
    local filename, rest = line:match('([^:]*):(.*)')
    local core_filename = filename:match('^%[string "(.*)"%]$')
    -- pass through frames that don't match this format
    -- this includes the initial line "stack traceback:"
    local new_frame = (core_filename or filename)..':'..rest
    table.insert(frames, new_frame)
    end
    -- the initial "stack traceback:" line was unindented and remains so
    return table.concat(frames, '\n\t')
    end