{"record":{"id":"9a7fa4809e32da2e","repo":"quarkusio/quarkus","slug":"bad-pet-9a7fa4","errorCode":null,"errorMessage":"bad pet","messagePattern":"bad pet","errorType":"http","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"integration-tests/reactive-messaging-hibernate-reactive/src/main/java/io/quarkus/it/kafka/PetProducer.java","lineNumber":28,"sourceCode":"import io.smallrye.mutiny.Uni;\nimport io.smallrye.reactive.messaging.kafka.transactions.KafkaTransactions;\n\n@Path(\"/kafka\")\npublic class PetProducer {\n\n    @Channel(\"pets\")\n    KafkaTransactions<Pet> petTransactions;\n\n    @POST\n    @Path(\"/pets\")\n    @WithTransaction\n    public Uni<Void> createPet(String name) {\n        Pet p = new Pet(name);\n        return petTransactions.withTransaction(e -> p.persist()\n                .map(pet -> (Pet) pet)\n                .invoke(pet -> {\n                    if (pet.name.equals(\"bad\")) {\n                        throw new IllegalArgumentException(\"bad pet\");\n                    }\n                })\n                .invoke(pet -> Log.infov(\"Persisted {0}\", pet))\n                .invoke(e::send)\n                .replaceWithVoid())\n                .onFailure().call(f -> {\n                    // apply any cleanup to do\n                    return Uni.createFrom().voidItem();\n                });\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":40,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/reactive-messaging-hibernate-reactive/src/main/java/io/quarkus/it/kafka/PetProducer.java#L10-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a pet name other than 'bad' when calling createPet if you expect success","If this is your code, move the validation before persist() so an invalid name never reaches the database","Review the .onFailure().call compensation chain to confirm the intended cleanup runs"],"exampleFix":"// before\n.invoke(pet -> {\n    if (pet.name.equals(\"bad\")) {\n        throw new IllegalArgumentException(\"bad pet\");\n    }\n})\n// after\nif (\"bad\".equals(name)) {\n    return Uni.createFrom().failure(new IllegalArgumentException(\"bad pet\"));\n}\nreturn petTransactions.withTransaction(e -> p.persist()...);","handlingStrategy":"validation","validationCode":"if (\"bad\".equals(name)) {\n    throw new IllegalArgumentException(\"bad pet\");\n}\n// then proceed with persist\n","typeGuard":null,"tryCatchPattern":"try {\n    petProducer.createPet(name).await().indefinitely();\n} catch (IllegalArgumentException e) {\n    Log.errorv(\"Rejected pet: {0}\", e.getMessage());\n}","preventionTips":["Validate entity fields before persist() rather than inside post-persist callbacks","Keep pipeline failures idempotent: never send to Kafka after a validation failure","Cover both success and compensation paths with integration tests"],"tags":["kafka","hibernate-reactive","validation","reactive-messaging"],"backgroundTag":"pre-persist-validation-failure","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}