apache/pulsar · error · RuntimeException

Unknown producer protobuf failure action

Error message

Unknown producer protobuf failure action 

What it means

CryptoUtils.getProducerCryptoFailureAction maps a CryptoSpec.FailureAction enum value to the client's ProducerCryptoFailureAction. The switch handles FAIL and SEND; any other value is unsupported and triggers this RuntimeException with the offending enum name appended. It indicates a failure-action value outside the supported producer set reached the converter.

Source

Thrown at pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/CryptoUtils.java:118

        try {
            Constructor<?> ctor = cryptoClass.getConstructor(Map.class);
            return (CryptoKeyReader) ctor.newInstance(configs);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException("Key reader class does not have constructor accepts map", e);
        } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
            throw new RuntimeException("Failed to create instance for key reader class", e);
        }
    }

    public static ProducerCryptoFailureAction getProducerCryptoFailureAction(CryptoSpec.FailureAction action) {
        switch (action) {
            case FAIL:
                return ProducerCryptoFailureAction.FAIL;
            case SEND:
                return ProducerCryptoFailureAction.SEND;
            default:
                throw new RuntimeException(
                        "Unknown producer protobuf failure action " + action.name());
        }
    }

    public static ConsumerCryptoFailureAction getConsumerCryptoFailureAction(CryptoSpec.FailureAction action) {
        switch (action) {
            case FAIL:
                return ConsumerCryptoFailureAction.FAIL;
            case DISCARD:
                return ConsumerCryptoFailureAction.DISCARD;
            case CONSUME:
                return ConsumerCryptoFailureAction.CONSUME;
            default:
                throw new RuntimeException(
                        "Unknown consumer protobuf failure action " + action.name());
        }
    }

View on GitHub (pinned to 820761864e)

Solutions

  1. Set the producer's CryptoSpec failureAction to FAIL or SEND only
  2. If you copied config from a consumer, switch to getConsumerCryptoFailureAction or use consumer-appropriate values (DISCARD/CONSUME)
  3. Align library versions so the enum sets match between the config producer and this converter

Example fix

// before
cryptoSpec.setFailureAction(CryptoSpec.FailureAction.DISCARD); // consumer-only
// after
cryptoSpec.setFailureAction(CryptoSpec.FailureAction.SEND); // valid for producer
Defensive patterns

Strategy: validation

Validate before calling

if (action != CryptoSpec.FailureAction.FAIL && action != CryptoSpec.FailureAction.SEND) {
    throw new IllegalArgumentException("Producer failureAction must be FAIL or SEND, got " + action);
}

Type guard

boolean isProducerAction(CryptoSpec.FailureAction a) {
    return a == CryptoSpec.FailureAction.FAIL || a == CryptoSpec.FailureAction.SEND;
}

Try / catch

try {
    ProducerCryptoFailureAction mapped = CryptoUtils.getProducerCryptoFailureAction(action);
} catch (RuntimeException e) {
    log.warn("Unsupported producer failure action, defaulting to FAIL", e);
    ProducerCryptoFailureAction mapped = ProducerCryptoFailureAction.FAIL;
}

Prevention

When it happens

Trigger: Calling getProducerCryptoFailureAction with a CryptoSpec.FailureAction value other than FAIL or SEND — e.g. a consumer-only action such as DISCARD or CONSUME passed into the producer-side converter, or a newly added enum value from a newer Pulsar version processed by an older converter.

Common situations: Copying a consumer crypto spec into a producer config; hand-written YAML/JSON function configs where the action name is for the consumer side; version skew between client library and functions utils after new enum constants were added.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/6b67a59b8b9cbf48. Report an issue: GitHub.