Add some error handling for Pty