The situation was worse since it happened already in the mempool where the pending transactions reside.
I am dabbling a bit in the Tezos currency and environment and find this 2 language projects interesting aimed to increase safety: https://github.com/metastatedev/juvix (alpha) and https://archetype-lang.org/ Not saying it might have helped in the concrete case.