apache/pulsar · error · IllegalArgumentException

Invalid schema type: ${valueSchema}

Error message

Invalid schema type: ${valueSchema}

What it means

CmdProduce.buildValueSchema maps the -vs/--value-schema argument to a Schema. Only a small set of prefixes/types is recognized (bytes, string, avro:, json:, etc.); anything else falls to the default branch and throws IllegalArgumentException naming the offending value.

Source

Thrown at pulsar-client-tools/src/main/java/org/apache/pulsar/client/cli/CmdProduce.java:369

                return new ValueSchema(Schema.bytes(), null);
            case "string":
                return new ValueSchema(Schema.autoProduceBytesOf(Schema.string()), null);
            default:
                if (valueSchema.startsWith("avro:")) {
                    String def = valueSchema.substring(5);
                    org.apache.avro.Schema avroNative = new org.apache.avro.Schema.Parser().parse(def);
                    Schema<?> generic = Schema.generic(
                            SchemaInfo.of("client", SchemaType.AVRO,
                                    def.getBytes(StandardCharsets.UTF_8), null));
                    return new ValueSchema(Schema.autoProduceBytesOf(generic), avroNative);
                } else if (valueSchema.startsWith("json:")) {
                    String def = valueSchema.substring(5);
                    Schema<?> generic = Schema.generic(
                            SchemaInfo.of("client", SchemaType.JSON,
                                    def.getBytes(StandardCharsets.UTF_8), null));
                    return new ValueSchema(Schema.autoProduceBytesOf(generic), null);
                }
                throw new IllegalArgumentException("Invalid schema type: " + valueSchema);
        }
    }

    private static ProducerEncryptionPolicy buildEncryptionPolicy(String keyName, String keyUri) {
        return ProducerEncryptionPolicy.builder()
                .publicKeyProvider(org.apache.pulsar.client.api.v5.auth.PemFileKeyProvider.builder()
                        .publicKey(keyName, fileUriToPath(keyUri))
                        .build())
                .keyName(keyName)
                .build();
    }

    @VisibleForTesting
    public String getWebSocketProduceUri(String topic) {
        String serviceURLWithoutTrailingSlash = serviceURL.substring(0,
                serviceURL.endsWith("/") ? serviceURL.length() - 1 : serviceURL.length());

        TopicName topicName = TopicName.get(topic);

View on GitHub (pinned to 820761864e)

Solutions

  1. Use a supported schema type: -vs bytes, -vs string, -vs 'avro:<schema definition>', or -vs 'json:<schema definition>'.
  2. Fix typos and check the exact prefix format (avro:/json: followed by the schema definition string).
  3. Omit -vs entirely to use the default schema if you just need raw bytes.
  4. Verify against this CLI's help (`pulsar-client produce --help`) rather than generic Pulsar docs.

Example fix

// before
pulsar-client produce t -m '42' -vs int32
// after
pulsar-client produce t -m '42' -vs 'json:{"type":"int"}'   // or -vs bytes/string/avro:<def>
Defensive patterns

Strategy: validation

Validate before calling

// bash: allow only supported -vs values
case "$VS" in ''|bytes|string|avro:*|json:*) ;; *) echo "invalid schema type: $VS"; exit 1;; esac

Type guard

function isValidValueSchema(vs) { return vs == null || ['bytes','string'].includes(vs) || /^(avro|json):/.test(vs); }

Try / catch

try { produce(vs); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Invalid schema type")) { /* correct -vs and retry */ } else throw e; }

Prevention

When it happens

Trigger: Running `pulsar-client produce ... -vs <value>` where <value> is not one of the supported types, e.g. -vs int8, -vs protobuf:, a typo like -vs bytes(, or an unsupported prefix like -vs keyvalue:.

Common situations: Copying schema strings from a full pulsar-client (which supports many SchemaType values) into this V5 CLI; misspelling avro/json; expecting primitive schema types like int32 to work.

Related errors


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