louislam/uptime-kuma · error · Error

Kafka Producer Brokers must be valid JSON: ${e.message}

Error message

Kafka Producer Brokers must be valid JSON: ${e.message}

What it means

validate() runs JSON.parse on kafkaProducerBrokers for kafka-producer monitors. It must be a JSON array of broker address strings (e.g. ["host:9092"]).

Source

Thrown at server/model/monitor.js:1649

            throw new Error(`Retry interval cannot be less than ${MIN_INTERVAL_SECOND} seconds`);
        }

        if (this.response_max_length !== undefined) {
            if (this.response_max_length < 0) {
                throw new Error(`Response max length cannot be less than 0`);
            }

            if (this.response_max_length > RESPONSE_BODY_LENGTH_MAX) {
                throw new Error(`Response max length cannot be more than ${RESPONSE_BODY_LENGTH_MAX} bytes`);
            }
        }

        // Validate JSON fields to prevent invalid JSON from being stored in database
        if (this.kafkaProducerBrokers) {
            try {
                JSON.parse(this.kafkaProducerBrokers);
            } catch (e) {
                throw new Error(`Kafka Producer Brokers must be valid JSON: ${e.message}`);
            }
        }

        if (this.kafkaProducerSaslOptions) {
            try {
                JSON.parse(this.kafkaProducerSaslOptions);
            } catch (e) {
                throw new Error(`Kafka Producer SASL Options must be valid JSON: ${e.message}`);
            }
        }

        if (this.rabbitmqNodes) {
            try {
                JSON.parse(this.rabbitmqNodes);
            } catch (e) {
                throw new Error(`RabbitMQ Nodes must be valid JSON: ${e.message}`);
            }
        }

View on GitHub (pinned to 6b5ea01557)

Solutions

  1. Provide brokers as a JSON array: ["host:9092"]
  2. Run JSON.parse on the value in a console before saving to catch syntax errors

Example fix

// before
monitor.kafkaProducerBrokers = "kafka:9092";

// after
monitor.kafkaProducerBrokers = '["kafka:9092"]';
Defensive patterns

Strategy: validation

Validate before calling

if (monitor.kafkaProducerBrokers) { JSON.parse(monitor.kafkaProducerBrokers); } // throws if invalid

Type guard

function isValidBrokers(v) {
  if (!v) return true;
  try { return Array.isArray(JSON.parse(v)) && JSON.parse(v).every(s => typeof s === "string"); }
  catch { return false; }
}

Try / catch

try { monitor.validate(); await save(monitor); } catch (e) { /* surface e.message */ }

Prevention

When it happens

Trigger: kafkaProducerBrokers holds a non-JSON string such as a comma-separated list ('host1:9092,host2:9092') instead of a JSON array.

Common situations: Pasting a comma-separated broker list from kafka docs; stray quotes or a trailing comma.

Related errors


AI-assisted analysis of louislam/uptime-kuma@6b5ea01557 (2026-08-12). Data as JSON: /api/errors/1640201d5d6bc638. Report an issue: GitHub.