logging before error is better