Simplify error checking in writeWithPendingDetection()