quarkusio/quarkus · error · IllegalArgumentException

bad pet

Error message

bad pet

What it means

This IllegalArgumentException('bad pet') is thrown deliberately inside the reactive persistence pipeline of PetProducer.createPet. The pet is persisted with Panache, and after persist completes the .invoke callback inspects the entity name; if the name equals 'bad' the exception is raised so the surrounding .onFailure().call compensation logic runs and the Kafka outbound message is never sent.

Source

Thrown at integration-tests/reactive-messaging-hibernate-reactive/src/main/java/io/quarkus/it/kafka/PetProducer.java:28

import io.smallrye.mutiny.Uni;
import io.smallrye.reactive.messaging.kafka.transactions.KafkaTransactions;

@Path("/kafka")
public class PetProducer {

    @Channel("pets")
    KafkaTransactions<Pet> petTransactions;

    @POST
    @Path("/pets")
    @WithTransaction
    public Uni<Void> createPet(String name) {
        Pet p = new Pet(name);
        return petTransactions.withTransaction(e -> p.persist()
                .map(pet -> (Pet) pet)
                .invoke(pet -> {
                    if (pet.name.equals("bad")) {
                        throw new IllegalArgumentException("bad pet");
                    }
                })
                .invoke(pet -> Log.infov("Persisted {0}", pet))
                .invoke(e::send)
                .replaceWithVoid())
                .onFailure().call(f -> {
                    // apply any cleanup to do
                    return Uni.createFrom().voidItem();
                });
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use a pet name other than 'bad' when calling createPet if you expect success
  2. If this is your code, move the validation before persist() so an invalid name never reaches the database
  3. Review the .onFailure().call compensation chain to confirm the intended cleanup runs

Example fix

// before
.invoke(pet -> {
    if (pet.name.equals("bad")) {
        throw new IllegalArgumentException("bad pet");
    }
})
// after
if ("bad".equals(name)) {
    return Uni.createFrom().failure(new IllegalArgumentException("bad pet"));
}
return petTransactions.withTransaction(e -> p.persist()...);
Defensive patterns

Strategy: validation

Validate before calling

if ("bad".equals(name)) {
    throw new IllegalArgumentException("bad pet");
}
// then proceed with persist

Try / catch

try {
    petProducer.createPet(name).await().indefinitely();
} catch (IllegalArgumentException e) {
    Log.errorv("Rejected pet: {0}", e.getMessage());
}

Prevention

When it happens

Trigger: Calling createPet("bad") on PetProducer: the Pet entity is persisted successfully, but the post-persist invoke sees pet.name.equals("bad") and throws before e::send publishes to Kafka.

Common situations: Integration tests exercising failure/compensation paths of reactive messaging with Hibernate Reactive; demos showing that a failure mid-pipeline prevents Kafka publication and triggers rollback/compensation.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/9a7fa4809e32da2e. Report an issue: GitHub.