improve error handling of wait_for_event