The documentation says that if your function fails it will back out, but it doesn’t say what constitutes a failure… A common practice would be to return false, but I’ve tried that and my error dialog shows correctly, but some of the actions executed so far persist (i.e. the transaction isn’t cancelled).
That’s great - it works. I present a Dialog to the user with a description/instructions about the problem, so they can try again, and this dialog still shows even if you do the error() after presenting it, which is perfect.
I would suggest making it clear in the docs for transaction that calling error() is the correct way to cause an explicit failure. It does say “if the function fails”, but since Lua is one of those languages you can just pick up and use without having actually learned it, it’s probably not obvious to inexperienced Lua users (like me) that’s how you deliberately cause a failure.
Yes I want to update the docs given that we can use error()to abort/rollback the transaction, but I wasn’t aware of this possibility. Actually the rollback mechanism was done just in case any other error in the Lua script happen (e.g. a syntax error or a function fails inside the transaction). But it can work explicitly with error() as we saw.