That’s about the most that can be done with these errors, and it should be done. Knowing what automation/template sensor sparked the error would be a great enhancement. The unfortunate truth is that we won’t be able to clean up the actual error.
Even if you had compile time errors, that Error he posted above wouldn’t be caught. It’s a situation where the current trigger doesn’t have ‘to_state’ in the dictionary. That wouldn’t be caught in any language until that moment in time in the code.