write function to wrap errors