picotool
picotool copied to clipboard
build command throws IndexError
An attempt to run a command
p8tool build --lua ./src/main.lua --gfx ./carts/assets.p8 ./carts/out.p8
throws a following Error
Traceback (most recent call last):
File "/Users/jakubgruszecki/Documents/picotool/p8tool", line 8, in <module>
sys.exit(tool.main(sys.argv[1:]))
File "/Users/jakubgruszecki/Documents/picotool/pico8/tool.py", line 596, in main
return args.func(args)
File "/Users/jakubgruszecki/Documents/picotool/pico8/build/build.py", line 258, in do_build
lua_path=getattr(args, 'lua_path', None))
File "/Users/jakubgruszecki/Documents/picotool/pico8/build/build.py", line 158, in _evaluate_require
_evaluate_require(reqd_lua, reqd_filepath, package_lua, lua_path=lua_path)
File "/Users/jakubgruszecki/Documents/picotool/pico8/build/build.py", line 158, in _evaluate_require
_evaluate_require(reqd_lua, reqd_filepath, package_lua, lua_path=lua_path)
File "/Users/jakubgruszecki/Documents/picotool/pico8/build/build.py", line 155, in _evaluate_require
reqd_lua.reparse(writer_cls=lua.LuaASTEchoWriter)
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 178, in reparse
version=self.version)
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 132, in from_lines
result.update_from_lines(lines)
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 141, in update_from_lines
self._lexer.process_lines(lines)
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lexer.py", line 479, in process_lines
for line in lines:
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 159, in to_lines
for line in writer.to_lines():
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 943, in to_lines
for chunk in self.walk():
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 247, in walk
for t in self._walk(self._root):
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 930, in _walk
for t in super()._walk(node):
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 228, in _walk
for t in result:
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 535, in _walk_Chunk
yield self._get_semis(node)
File "/Users/jakubgruszecki/Documents/picotool/pico8/lua/lua.py", line 522, in _get_semis
if self._tokens[self._pos].matches(lexer.TokSymbol(b';')):
IndexError: list index out of range
My project on which picotool crashes is in this repo: https://github.com/ditrytus/coffee-central
The error was caused by of one of my .lua files missing an empty line at the end.
I don't know why is that required, but if it is, then a more readable error message would help.
No guaranteed fix, but for local work I use my own branch of picotool which adds a bunch of try-except, error messages and empty checks. You may find some ideas here:
https://github.com/hsandt/picotool/commit/b7c5dbc11b5d1d9949e476c77b3c53a83776b5b8#diff-04cb0a489a4e9fbe769aec633ed314ebR546