Refactor xpcall error handler in runtests.lua