Reworked error stack handling to ensure stack is always set