about summary refs log tree commit diff stats
path: root/source_file.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-11-18 11:30:57 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-11-18 11:32:01 -0800
commit007b965b11b681550ee2e2244a2f53e64e88697d (patch)
treee3bff0e0d71e896ea1d954ae7715f672b247bf0e /source_file.lua
parent5cce5115507800eeca7ba9c271e07c23473228f4 (diff)
downloadlines.love-007b965b11b681550ee2e2244a2f53e64e88697d.tar.gz
audit all asserts
Each one should provide a message that will show up within LÖVE. Stop
relying on nearby prints to the terminal.

I also found some unnecessary ones.

There is some potential here for performance regressions: the format()
calls will trigger whether or not the assertion fails, and cause
allocations. So far Lua's GC seems good enough to manage the load even
with Moby Dick, even in some situations that caused issues in the past
like undo.
Diffstat (limited to 'source_file.lua')
-rw-r--r--source_file.lua13
1 files changed, 5 insertions, 8 deletions
diff --git a/source_file.lua b/source_file.lua
index dbb6f95..6d04f6b 100644
--- a/source_file.lua
+++ b/source_file.lua
@@ -63,7 +63,7 @@ function load_drawing(infile_next_line)
   local drawing = {mode='drawing', h=256/2, points={}, shapes={}, pending={}}
   while true do
     local line = infile_next_line()
-    assert(line)
+    assert(line, 'drawing in file is incomplete')
     if line == '```' then break end
     local shape = json.decode(line)
     if shape.mode == 'freehand' then
@@ -88,8 +88,7 @@ function load_drawing(infile_next_line)
     elseif shape.mode == 'deleted' then
       -- ignore
     else
-      print(shape.mode)
-      assert(false)
+      assert(false, ('unknown drawing mode %s'):format(shape.mode))
     end
     table.insert(drawing.shapes, shape)
   end
@@ -123,8 +122,7 @@ function store_drawing(outfile, drawing)
     elseif shape.mode == 'deleted' then
       -- ignore
     else
-      print(shape.mode)
-      assert(false)
+      assert(false, ('unknown drawing mode %s'):format(shape.mode))
     end
   end
   outfile:write('```\n')
@@ -162,7 +160,7 @@ function load_drawing_from_array(iter, a, i)
   local line
   while true do
     i, line = iter(a, i)
-    assert(i)
+    assert(i, 'drawing in array is incomplete')
 --?     print(i)
     if line == '```' then break end
     local shape = json.decode(line)
@@ -188,8 +186,7 @@ function load_drawing_from_array(iter, a, i)
     elseif shape.mode == 'deleted' then
       -- ignore
     else
-      print(shape.mode)
-      assert(false)
+      assert(false, ('unknown drawing mode %s'):format(shape.mode))
     end
     table.insert(drawing.shapes, shape)
   end