Generalize failOnError