Pact "No consumer state handler found for state" in CI
A pact interaction declares "Given <state>", and provider verification has no matching state handler to set up that precondition. Without the handler the provider cannot reach the expected state, so the interaction fails.
What this error means
Verification fails with "No consumer state handler found for consumer ... and state ...", or "state change request failed", for an interaction that uses a "Given" provider state.
Failures:
1) Verifying a pact between web-consumer and orders-provider
Given order 42 exists
WARN: State change ignored - no matching handler
No consumer state handler found for state "order 42 exists"Common causes
The state string is not registered on the provider
The handler map has no entry whose key matches the exact "Given" string from the pact, so no setup runs for that state.
The state string drifted between consumer and provider
The consumer changed the wording of the provider state but the provider handler still keys on the old text, so lookup misses.
How to fix it
Register a handler for the exact state string
- Copy the state string verbatim from the failing interaction.
- Add a
stateHandlersentry with that exact key. - Seed the data the interaction needs inside the handler.
stateHandlers: {
'order 42 exists': async () => {
await db.orders.insert({ id: 42, total: 19.99 });
},
}Keep provider state strings in sync
Treat the "Given" text as a contract; when the consumer changes it, update the provider handler key to match.
How to prevent it
- Register a handler for every provider state the pacts declare.
- Match handler keys to the exact "Given" strings, whitespace included.
- Fail verification when a state has no handler rather than ignoring it.