Properly wrap IO actions with error handler.