fix build and add error trap