Fork 0
Alternative Lua assert function, with better error messages.
Go to file
Jon Michael Aanes e839318682
LÖVE/Lua Library / Static-Analysis (push) Successful in 3s Details
Update library
2024-04-14 14:43:43 +02:00
.gitea/workflows Update library 2024-04-14 14:43:43 +02:00
test Added a bunch of constant evaluations 2018-03-23 12:26:45 +01:00
.gitignore The lost additions 2023-12-12 23:28:25 +01:00
.luacheckrc Workflows 2023-12-12 23:30:19 +01:00
Lexer.lua Initial commit on assert-gooder. An improved version of `assert` 2017-10-28 12:44:53 +02:00
Parser.lua Added a bunch of constant evaluations 2018-03-23 12:26:45 +01:00
README.md Initial Readme 2017-10-28 13:47:19 +02:00
assert-gooder.lua The lost additions 2023-12-12 23:28:25 +01:00
init.lua Improved robustness. 2017-11-05 11:31:46 +01:00
lua_lang.lua The lost additions 2023-12-12 23:28:25 +01:00


Assert Gooder

Lua library implementing an alternative version of Lua's assert function, giving much better error messages, when asserts fails. It does this by analysing the body of the assert, and figuring out what the failing assert call is attempting to test against.


function f (a)
	assert(type(a) == 'string')


Without assert-gooder, the above code would fail with the error message assertion failed!. With assert-gooder, it will fail with this error message: assertion failed! bad argument #1 'a' to 'f' (string expected, but got number: 42),


Assertions are useful to ensure internal consistency, when you're writing code in a hurry, but in Lua (and most other languages), these assert constructs never produce useful error messages, but rather unhelpful assert failed! errors and a stack trace.

By making it a runtime library, instead of a "compile-time" rewrite, we gain flexibility. It's much easier to import a library, than restructuring then compile pipeline. It also means that we have access to runtime values, allowing even more helpful messages.


Download, and use assert = require "assert-gooder" to overwrite Lua's default assert with assert-gooder.


"THE BEER-WARE LICENSE" (Revision 42):
<jonjmaa@gmail.com> wrote this library.  As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy me a beer in return.