Skip to content
Latchkey

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.

Pact
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

  1. Copy the state string verbatim from the failing interaction.
  2. Add a stateHandlers entry with that exact key.
  3. Seed the data the interaction needs inside the handler.
provider.verify.js
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.

Frequently asked questions

What causes ""No consumer state handler found""?
The handler map has no entry whose key matches the exact "Given" string from the pact, so no setup runs for that state.
How do I fix "No consumer state handler found"?
Register a handler for the exact state string

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card