Is there a good way to just exit out in the middle of an Update call and not change the state?
If we had a complex function call that modified a load of data structures, and there was an error right at the end, how would we keep the integrity of the data? Writing a commit/rollback system for our ORM would be possible but… horrible.
EDIT - just saw this. Discard state changes from update call without trap. Yes we’d like to be able to return a message to the user if possible.
If it’s in a shared/async context you can try throwing asynchronous errors
I think we’re going to bite the bullet and making a Transaction wrapper for all our complex queries. No idea where to start!
One thing to be wary of is changes that happen during your intercanister calls. Your transaction wrapper will need to handle this or throw if the underlying data changed. An alternative is to lock a record when it goes into a trx, but then you will slow your app. No easy fixes.
I bet there are some js or rust transaction libraries that would be decent patterns to follow, especially with the move to async js recently.
An update to this pattern (candy_library/properties.mo at 88de87b85006d22480829bb55336407f9266a12e · aramakme/candy_library · GitHub) with a transaction layer might be a place to start. Most of this came from @quint so he may have some ideas.
well this was the first step. I was thinking of having a Transaction class that could store a list of updates, but you can’t have an array of different generic types. I just need to store a load of queries but not pull the trigger until all the validation is done. I’ll get there haha.