Error code in hass

My automations no longer work and when I try to delete them I get this error message “Error loading automation (500).” ?

One more question…
Why is it not possible to delete old entities after the device is removed from the system