How to cancel an order transition if failure is detected in Commerce 2 / State Machine I'm trying to plug into order transitions in order to send my order to a custom fulfillment system.

I have a transition called "send_to_fulfillment", and order states "reviewing" and "sent_to_fulfillment".

I'm hooking into the commerce_order.send_to_fulfillment.pre_transition event. What I can't figure out is how to cancel the transition if the process fails. I can certainly just throw an exception and let the site die, but I'd prefer to be able to elegantly stop the transition and inform the user of the error.

Any tips? I've tried WorkflowTransitionEvent::stopPropagation which didn't do it, and I can't seem to find it documented anywhere.
We don't have a "cancel" or "reverse" feature right now, but it would be worth a feature request in the State Machine queue. The main thing you / we'll need to overcome is what to do in the event a transition in progress has already saved data, triggered 3rd party services, etc. Presumably, there are certain things that should prevent a transition from being reversed (e.g. I've refunded a payment card and therefore must move the order to a canceled or at least unpaid state). However, other things may fall somewhere in the middle ... be allowable and not prevent reversal.

Lisa had a great idea, too, in that you could define the reverse transition explicitly yourself and trigger it in the event that you had a failure condition in your active transition. That would allow you to encode your own logic for checking / reversing transition side effects.