{"record":{"id":"64d30372c6a25648","repo":"sipeed/picoclaw","slug":"mqtt-broker-is-required","errorCode":null,"errorMessage":"mqtt broker is required","messagePattern":"mqtt broker is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/channels/mqtt/mqtt.go","lineNumber":40,"sourceCode":"// mqttPayload is the JSON payload for both inbound and outbound messages.\ntype mqttPayload struct {\n\tText string `json:\"text\"`\n}\n\n// MQTTChannel implements the Channel interface for MQTT-based communication.\ntype MQTTChannel struct {\n\t*channels.BaseChannel\n\tbc       *config.Channel\n\tcfg      *config.MQTTSettings\n\tclient   pahomqtt.Client\n\tqos      byte\n\tclientID string\n}\n\n// NewMQTTChannel creates a new MQTT channel instance.\nfunc NewMQTTChannel(bc *config.Channel, cfg *config.MQTTSettings, b *bus.MessageBus) (*MQTTChannel, error) {\n\tif cfg.Broker == \"\" {\n\t\treturn nil, fmt.Errorf(\"mqtt broker is required\")\n\t}\n\tif cfg.AgentID == \"\" {\n\t\treturn nil, fmt.Errorf(\"mqtt agent_id is required\")\n\t}\n\n\tbase := channels.NewBaseChannel(\"mqtt\", cfg, b, bc.AllowFrom,\n\t\tchannels.WithGroupTrigger(bc.GroupTrigger),\n\t\tchannels.WithReasoningChannelID(bc.ReasoningChannelID),\n\t)\n\n\tmqttClientID := cfg.ClientID\n\tif mqttClientID == \"\" {\n\t\tvar suffix [4]byte\n\t\t_, _ = rand.Read(suffix[:])\n\t\tmqttClientID = fmt.Sprintf(\"picoclaw-mqtt-%s-%s\", cfg.AgentID, hex.EncodeToString(suffix[:]))\n\t}\n\n\treturn &MQTTChannel{","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/mqtt/mqtt.go#L22-L58","documentation":"Raised by NewMQTTChannel when constructing an MQTT channel with an empty MQTTSettings.Broker value. The broker URL is the endpoint the paho MQTT client must dial, so a blank broker leaves the channel with no host to connect to; the guard rejects channel creation before any client is instantiated. Fix by setting a non-empty broker address (e.g. tcp://host:1883) in the channel's MQTT settings.","triggerScenarios":"Thrown at pkg/channels/mqtt/mqtt.go:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set mqtt.broker in the channel config (e.g. tcp://broker:1883)","Validate configuration before channel creation","Fix the config; retry is meaningless without a broker address"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","contentChangedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}