lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I tend to get tracebacks like these:

Error: LuaRocks 2.0.7 bug (please report at
luarocks-developers@lists.sourceforge.net).
...r/luarocks/share/lua/5.1//luarocks/fs/unix/tools.lua:135: assertion failed!
stack traceback:
	[C]: in function 'assert'
	...r/luarocks/share/lua/5.1//luarocks/fs/unix/tools.lua:135: in
function 'delete'
	.../user/luarocks/share/lua/5.1//luarocks/fetch/git.lua:51: in
function <.../user/luarocks/share/lua/5.1//luarocks/fetch/git.lua:16>
	(tail call): ?
	...ome/user/luarocks/share/lua/5.1//luarocks/unpack.lua:35: in
function 'unpack_rockspec'
	...ome/user/luarocks/share/lua/5.1//luarocks/unpack.lua:107: in
function <...ome/user/luarocks/share/lua/5.1//luarocks/unpack.lua:84>
	(tail call): ?
	(tail call): ?
	[C]: in function 'xpcall'
	...er/luarocks/share/lua/5.1//luarocks/command_line.lua:145: in
function 'run_command'
	/home/user/luarocks/bin/luarocks:23: in main chunk
	[C]: ?

In the interest of readability, is it really worth it to truncate the
heads of the file paths?  It was discussed previously in [1].  A large
percentage of typical paths slightly exceed 60 characters, and it's
not like paths often greatly exceed 60 characters, and even in the
rare cases they do I'd more often than not want the full path anyway.

The truncated file paths are taken from the `short_src` debuginfo,
whose length is controlled by `LUA_IDSIZE` (default 60).  However, I
see the full file name is separately stored in the `source` debuginfo
and even gets carried through the luac bytecode serialization.  So,
`luaL_traceback` is able to utilize `ar.source` rather than
`ar.short_src` if `ar.source` is a file name (@), leading to
more-or-less this:


--- lua-5.2.0-rc4/src/lauxlib.c
+++ lua-5.2.0-rc4-patch//src/lauxlib.c
@@ -128,7 +128,7 @@
     }
     else {
       lua_getinfo(L1, "Slnt", &ar);
-      lua_pushfstring(L, "\n\t%s:", ar.short_src);
+      lua_pushfstring(L, "\n\t%s:", ar.source[0] == '@' ? ar.source+1
: ar.short_src);
       if (ar.currentline > 0)
         lua_pushfstring(L, "%d:", ar.currentline);
       lua_pushliteral(L, " in ");
@@ -184,7 +184,7 @@
   if (lua_getstack(L, level, &ar)) {  /* check function at level */
     lua_getinfo(L, "Sl", &ar);  /* get info about it */
     if (ar.currentline > 0) {  /* is there info? */
-      lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
+      lua_pushfstring(L, "%s:%d: ", ar.source[0] == '@' ? ar.source+1
: ar.short_src, ar.currentline);
       return;
     }
   }


[1] http://lua-users.org/lists/lua-l/2006-03/msg00101.html