{"record":{"id":"dfff6aa44d903426","repo":"louislam/uptime-kuma","slug":"kafka-producer-sasl-options-must-be-valid-json","errorCode":null,"errorMessage":"Kafka Producer SASL Options must be valid JSON: ${e.message}","messagePattern":"Kafka Producer SASL Options must be valid JSON: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/model/monitor.js","lineNumber":1657,"sourceCode":"            if (this.response_max_length > RESPONSE_BODY_LENGTH_MAX) {\n                throw new Error(`Response max length cannot be more than ${RESPONSE_BODY_LENGTH_MAX} bytes`);\n            }\n        }\n\n        // Validate JSON fields to prevent invalid JSON from being stored in database\n        if (this.kafkaProducerBrokers) {\n            try {\n                JSON.parse(this.kafkaProducerBrokers);\n            } catch (e) {\n                throw new Error(`Kafka Producer Brokers must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.kafkaProducerSaslOptions) {\n            try {\n                JSON.parse(this.kafkaProducerSaslOptions);\n            } catch (e) {\n                throw new Error(`Kafka Producer SASL Options must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.rabbitmqNodes) {\n            try {\n                JSON.parse(this.rabbitmqNodes);\n            } catch (e) {\n                throw new Error(`RabbitMQ Nodes must be valid JSON: ${e.message}`);\n            }\n        }\n\n        if (this.conditions) {\n            try {\n                JSON.parse(this.conditions);\n            } catch (e) {\n                throw new Error(`Conditions must be valid JSON: ${e.message}`);\n            }\n        }","sourceCodeStart":1639,"sourceCodeEnd":1675,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/model/monitor.js#L1639-L1675","documentation":"validate() runs JSON.parse on kafkaProducerSaslOptions for kafka-producer monitors. It must be a JSON object (e.g. {\"mechanism\":\"plain\",\"username\":\"u\",\"password\":\"p\"}) or empty when SASL is unused.","triggerScenarios":"kafkaProducerSaslOptions is not parseable as a JSON object, e.g. typed as key=value pairs or missing braces.","commonSituations":"User typed SASL config as plain text instead of JSON; partial paste missing closing brace.","solutions":["Provide SASL options as a JSON object, or leave empty/omit when not using SASL","Validate the value parses as an object (not array/primitive) before saving"],"exampleFix":"// before\nmonitor.kafkaProducerSaslOptions = \"mechanism=plain,username=u,password=p\";\n\n// after\nmonitor.kafkaProducerSaslOptions = '{\"mechanism\":\"plain\",\"username\":\"u\",\"password\":\"p\"}';","handlingStrategy":"validation","validationCode":"if (monitor.kafkaProducerSaslOptions) {\n  const v = JSON.parse(monitor.kafkaProducerSaslOptions);\n  if (typeof v !== \"object\" || v === null || Array.isArray(v)) throw new Error(\"SASL options must be a JSON object\");\n}","typeGuard":"function isValidSasl(v) {\n  if (!v) return true;\n  try { const o = JSON.parse(v); return o && typeof o === \"object\" && !Array.isArray(o); }\n  catch { return false; }\n}","tryCatchPattern":"try { monitor.validate(); await save(monitor); } catch (e) { /* surface e.message */ }","preventionTips":["Store SASL options as a JSON object; omit when SASL is unused","Never type SASL config as key=value text"],"tags":["kafka","json","validation","config","sasl"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}