Handling errors correctly in saveImage