Merge text0

I've tested both syntax error and run-time error flows.
This commit is contained in:
Kartik K. Agaram 2023-11-10 10:15:35 -08:00
commit 279c42966b
1 changed files with 35 additions and 4 deletions

View File

@ -201,7 +201,7 @@ function live.run(buf)
local status, err = live.eval(buf, definition_name)
if not status then
-- throw an error
live.send_to_driver('ERROR '..tostring(err))
live.send_to_driver('ERROR '..cleaned_up_frame(tostring(err)))
return
end
-- eval succeeded without errors; persist the definition
@ -374,9 +374,10 @@ end
-- return nil to continue the event loop, non-nil to quit
function live.handle_error(err)
Mode = 'error'
local stack_trace = debug.traceback('Error: ' .. tostring(err), --[[stack frame]]2)
live.send_run_time_error_to_driver(stack_trace)
Error_message = 'Something is wrong. Sorry!\n\n'..stack_trace..'\n\n'..
local callstack = debug.traceback('', --[[stack frame]]2)
local cleaned_up_error = 'Error: ' .. cleaned_up_frame(tostring(err))..'\n'..cleaned_up_callstack(callstack)
live.send_run_time_error_to_driver(cleaned_up_error)
Error_message = 'Something is wrong. Sorry!\n\n'..cleaned_up_error..'\n\n'..
"(Note: function names above don't include outer tables. So functions like on.draw might show up as just 'draw', etc.)\n\n"..
'Options:\n'..
'- press "ctrl+c" (without the quotes) to copy this message to your clipboard to send to me: ak@akkartik.com\n'..
@ -388,3 +389,33 @@ function live.handle_error(err)
end
print(Error_message)
end
-- 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.
-- It also strips out the numeric prefixes we introduce in filenames.
function cleaned_up_callstack(callstack)
local frames = {}
for frame in string.gmatch(callstack, '[^\n]+\n*') do
table.insert(frames, cleaned_up_frame(frame))
end
-- the initial "stack traceback:" line was unindented and remains so
return table.concat(frames, '\n\t')
end
function cleaned_up_frame(frame)
local line = frame:gsub('^%s*(.-)\n?$', '%1')
local filename, rest = line:match('([^:]*):(.*)')
return cleaned_up_filename(filename)..':'..rest
end
function cleaned_up_filename(filename)
-- pass through frames that don't match this format
-- this includes the initial line "stack traceback:"
local core_filename = filename:match('^%[string "(.*)"%]$')
if core_filename == nil then return filename end
-- strip out the numeric prefixes we introduce in filenames
local _, core_filename2 = core_filename:match('^(%d+)-(.+)')
return core_filename2 or core_filename
end