Properly log errors in main thread