Exception message from failed transaction function

Hi XTDB community!

I make heavy use of transaction functions via a macro I wrote. I often do a lot of validation checking inside these transaction functions, throwing an exception (and therefore aborting the transaction) if a validation check fails (an example).

It would be very nice if I could catch the exception, ultimately to provide more informative messages for users, but I’m unsure of how to do it. First, you can’t catch the exception directly, since the actual transaction function is run in a different execution environment and xtdb itself catches any exceptions. There’s xt/tx-committed? but that only gives you a boolean. Does anybody have advice on how I could do this?

Unfortunately, I can’t think of a good way to do this without adding the functionality to XT itself. There’s a non-zero chance @refset has a handy gist somewhere, though. He’s back tomorrow. :slight_smile:

1 Like

Depending on how involved it is, I want this badly enough that I’d be interested in writing a PR if the XTDB team would consider reviewing it :slight_smile: If that’s so, then a pointer on the relevant file(s) for this would be helpful, and I could come back with something.

2 Likes

Short of a longer response, there’s this thread on Clojurians Slack with various tips and ideas: Slack

There’s also been this recent issue created with a concrete suggestion that might be useful for you to think about and comment on: Can failed transactions store their error information to be accessed through an XTDB API? · Issue #1672 · xtdb/xtdb · GitHub (also Could xt/with-tx indicate errors in the transaction in its return value? · Issue #1671 · xtdb/xtdb · GitHub)

I’ll circle back to this (and that issue) in a day or two(!)

Here are permalinks for the Slack threads:

xtdb 2021-11-23 | Slack Archive (which @refset pointed to)

xtdb 2021-11-01 | Slack Archive (a longer, more detailed thread which the original thread points to)

In case they see it, huge thanks to the Clojurians Log maintainers. I sincerely doubt Clojurians will receive a Pro account from Slack indefinitely so the Slack archive is still incredibly useful. There are also likely to be people who stumble upon this thread who are either (a) not Clojure developers or (b) not on Clojurians. Clojurians Log is very web-friendly and I’d encourage everyone to link to it if we absolutely have to back-reference Slack. Better yet is to digest the Slack thread into a concise explanation inside Discourse itself, though. :slight_smile:

1 Like