improved error handling to stop logging bogus stack traces