some more logs

The previous commit was super useful. The links are not actually being
lost when I exit pensieve. Instead, they're somehow not being set in
some code path that I haven't tracked down yet.

The important thing is, I've been missing things because I wasn't
running it from a terminal. prints (that the links are empty) were
disappearing that would have helped diagnose it. Lesson learned: always
send error prints to the log as well. At least there we have a hope of
spotting them.

Once we start emitting prints to the log, also include the function
name. On errors so far we've not bothered because the default LOVE error
handler shows the stack trace. However the logs don't record the stack,
and we might go looking at them long after the app crashes. The print
doesn't need function names, but the log does so we'll just
lowest-common-denominator both.
This commit is contained in:
Kartik K. Agaram 2023-03-08 18:23:37 -08:00
parent da397e7154
commit eef0e2bc3b
4 changed files with 25 additions and 20 deletions

View File

@ -235,7 +235,7 @@ function keychord_press_on_command_palette(chord, key)
-- clean up some columns if possible
if Cursor_pane.col < 45 then
while #Surface > 50 do
print('dropping '..Surface[#Surface].name)
print_and_log('keychord_press (palette) return: dropping '..Surface[#Surface].name)
love.filesystem.append(Overflow_file, os.date('%Y-%m-%d %H:%M:%S ')..Surface[#Surface].name..'\n')
table.remove(Surface)
end
@ -543,7 +543,7 @@ function run_command(cmd, args)
elseif cmd == 'cursor to previous word' then
command.send_key_to_current_pane('M-left', 'left')
else
print(('not implemented yet: %s'):format(function_name))
print_and_log(('run_command: not implemented yet: %s'):format(function_name))
end
end
@ -591,7 +591,7 @@ function create_column(column_name)
-- a column on the surface, but there's no file backing it. You can still
-- edit it later and create a file for it. But if you just quit, the
-- column will silently disappear after restart.
print('file not found: '..column_name)
print_and_log('create_column: file not found: '..column_name)
else
-- delegate to one of various helpers based on the column name
local column = {name=column_name}
@ -1211,7 +1211,7 @@ function command.rename_link(args)
else
target = Links[pane.id][from]
end
print('renaming link', from, 'of', pane, 'to', to)
print_and_log('renaming link', from, 'of', pane, 'to', to)
if Links[pane.id][to] and not array.find(Non_unique_edges, to) then
add_error(('%s already has a %s note'):format(pane.id, to))
return
@ -1248,7 +1248,7 @@ function command.clear_link(rel)
if type(Links[pane.id][rel]) == 'table' then
add_error(('%s is a non-unique link; clearing all such links'):format(rel))
end
print(('clearing link %s of %s (used to point to %s)'):format(rel, pane.id, Links[pane.id][rel]))
print_and_log(('clearing link %s of %s (used to point to %s)'):format(rel, pane.id, Links[pane.id][rel]))
Links[pane.id][rel] = nil
schedule_save(pane)
stop_editing(pane)
@ -1586,7 +1586,7 @@ end
function new_pane()
local t = os.time()
local id = os.date('%Y/%m/%d/%H-%M-%S', t)
print('creating directory '..Directory..dirname(id))
print_and_log('new_pane: creating directory '..Directory..dirname(id))
local status = love.filesystem.createDirectory(Directory..dirname(id))
assert(status)
Links[id] = {}

View File

@ -1,5 +1,6 @@
function add_error(err)
print(err)
log(2, 'add_error: '..err)
table.insert(Error_log.lines, {mode='text', data=err})
table.insert(Error_log.line_cache, {})
Current_error = err

View File

@ -104,7 +104,7 @@ function load_drawing(infile_next_line)
elseif shape.mode == 'deleted' then
-- ignore
else
print(shape.mode)
print_and_log('load_drawing: '..shape.mode)
assert(false)
end
table.insert(drawing.shapes, shape)
@ -139,7 +139,7 @@ function store_drawing(outfile, drawing)
elseif shape.mode == 'deleted' then
-- ignore
else
print(shape.mode)
print_and_log('store_drawing: '..shape.mode)
assert(false)
end
end
@ -160,8 +160,7 @@ function save_links(id)
local links_filename = Directory..id..'.json'
log(2, 'save_links: '..id)
if empty(Links[id]) then
log(2, 'save_links: no links; getting rid of .json if it exists')
print('no links; getting rid of .json if it exists')
print_and_log('save_links: no links; getting rid of .json if it exists')
love.filesystem.remove(links_filename)
return
end
@ -232,7 +231,7 @@ function load_drawing_from_array(iter, a, i)
elseif shape.mode == 'deleted' then
-- ignore
else
print(shape.mode)
print_and_log('load_drawing_from_array: '..shape.mode)
assert(false)
end
table.insert(drawing.shapes, shape)

23
run.lua
View File

@ -140,8 +140,8 @@ function run.initialize(arg)
end
love.window.setTitle('pensieve.love')
print('reading notes from '..love.filesystem.getSaveDirectory()..'/'..Directory)
print('put any notes there (and make frequent backups)')
print_and_log('reading notes from '..love.filesystem.getSaveDirectory()..'/'..Directory)
print_and_log('put any notes there (and make frequent backups)')
if Settings.width then
run.load_settings()
@ -166,6 +166,11 @@ function run.initialize(arg)
end
end
function print_and_log(s)
print(s)
log(3, s)
end
function run.load_settings()
-- determine default dimensions and flags
App.screen.width, App.screen.height, App.screen.flags = love.window.getMode()
@ -261,7 +266,7 @@ function refresh_pane_height(pane)
-- nothing
y = y + Drawing.pixels(line.h, Display_settings.column_width) + Drawing_padding_height
else
print(line.mode)
print_and_log('refresh_pane_height: '..line.mode)
assert(false)
end
end
@ -362,7 +367,7 @@ function run.draw()
end
end
else
print(Display_settings.mode)
print_and_log('run.draw: '..Display_settings.mode)
assert(false)
end
if Grab_pane then
@ -639,7 +644,7 @@ function run.mouse_press(x,y, mouse_button)
end
end
else
print(Display_settings.mode)
print_and_log('run.mouse_press: '..Display_settings.mode)
assert(false)
end
end
@ -753,7 +758,7 @@ function run.text_input(t)
end
end
else
print(Display_settings.mode)
print_and_log('run.text_input: '..Display_settings.mode)
assert(false)
end
end
@ -825,7 +830,7 @@ function run.keychord_press(chord, key)
keychord_press_in_maximize_mode(chord, key)
end
else
print(Display_settings.mode)
print_and_log('run.keychord_press: '..Display_settings.mode)
assert(false)
end
end
@ -1114,12 +1119,12 @@ end
function keychord_press_in_maximize_mode(chord, key)
if Cursor_pane.col < 1 then
print('no current note to edit')
print_and_log('keychord_press (maximized): no current note to edit')
return
end
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
if pane == nil then
print('no current note to edit')
print_and_log('keychord_press (maximized): no current note to edit')
return
end
if pane.editable then