Improve error handling and reporting

Change-Id: Ie509254311938bbb0219540e90bc7cf155b152c6