Fix potential crash when error.stack is undefined