Fix undef deref in error handling