1
0
Alternative Lua assert function, with better error messages.
Go to file
2025-04-17 17:04:38 +02:00
.gitea/workflows 🤖 Repository layout updated to latest version 2025-04-17 16:36:19 +02:00
test Bumped workflows to v6.19 2024-04-26 11:48:20 +02:00
.gitignore 🤖 Repository layout updated to latest version 2025-04-17 17:04:38 +02:00
.luacheckrc 🤖 Repository layout updated to latest version 2025-04-17 16:36:19 +02:00
assert-gooder.lua 🤖 Bumped version to 0.5.3 2025-04-17 16:38:22 +02:00
init.lua 🤖 Repository layout updated to latest version 2025-04-17 16:36:19 +02:00
Lexer.lua Initial commit on assert-gooder. An improved version of assert 2017-10-28 12:44:53 +02:00
LICENSE 🤖 Repository layout updated to latest version 2025-04-17 16:36:19 +02:00
lua_lang.lua The lost additions 2023-12-12 23:28:25 +01:00
Parser.lua Added a bunch of constant evaluations 2018-03-23 12:26:45 +01:00
README.md 🤖 Repository layout updated to latest version 2025-04-17 16:38:00 +02:00

Assert Gooder

Supercharged assert replacement.

Lua Library that replaces the default assert function with one that can emit improved error messages. The improved assert function parses the assert condition, inspects the state of the program and emits an improved error message.

Example

function f (a)

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


 end

 f(42)

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),

Motivation

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.

Setup

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

Dependencies

This project requires PUC Lua 5.1 or LuaJIT. Newer versions of PUC Lua are not supported.

This project does not have any library requirements 😎

Contributing

Feel free to submit pull requests. Please follow the Code Conventions when doing so.

License

MIT License

Copyright (c) 2017-2025 Jon Michael Aanes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.