{"record":{"id":"cae65b405850aa4d","repo":"sipeed/picoclaw","slug":"mqtt-connect-failed-w","errorCode":null,"errorMessage":"mqtt connect failed: %w","messagePattern":"mqtt connect failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/channels/mqtt/mqtt.go","lineNumber":111,"sourceCode":"\topts.SetOnConnectHandler(func(client pahomqtt.Client) {\n\t\tlogger.InfoC(\"mqtt\", \"MQTT connected, subscribing to inbound topic\")\n\t\terr := c.subscribe(client)\n\t\tonce.Do(func() { firstSubscribe <- err })\n\t})\n\n\topts.SetConnectionLostHandler(func(_ pahomqtt.Client, err error) {\n\t\tlogger.WarnCF(\"mqtt\", \"MQTT connection lost\", map[string]any{\"error\": err.Error()})\n\t})\n\n\tclient := pahomqtt.NewClient(opts)\n\ttoken := client.Connect()\n\tif !token.WaitTimeout(10 * time.Second) {\n\t\tclient.Disconnect(250)\n\t\treturn fmt.Errorf(\"mqtt connect timed out after 10s (broker: %s)\", c.cfg.Broker)\n\t}\n\tif err := token.Error(); err != nil {\n\t\tclient.Disconnect(250)\n\t\treturn fmt.Errorf(\"mqtt connect failed: %w\", err)\n\t}\n\n\tif err := <-firstSubscribe; err != nil {\n\t\tclient.Disconnect(250)\n\t\treturn fmt.Errorf(\"mqtt subscribe failed: %w\", err)\n\t}\n\n\tc.client = client\n\tc.SetRunning(true)\n\n\tlogger.InfoCF(\"mqtt\", \"MQTT channel started\", map[string]any{\n\t\t\"broker\":   c.cfg.Broker,\n\t\t\"agent_id\": c.cfg.AgentID,\n\t})\n\treturn nil\n}\n\n// topicPrefix returns the configured topic prefix, normalizing slashes.","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/mqtt/mqtt.go#L93-L129","documentation":"Fired in MQTTChannel.Start when the paho client's Connect token completes but reports an error (broker unreachable, auth rejected, TLS failure) within the 10-second wait. The connection is dropped (Disconnect 250ms) and Start fails with the wrapped token error.","triggerScenarios":"Thrown at pkg/channels/mqtt/mqtt.go:111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify broker URL, username/password, and TLS settings","Check broker logs for the rejection reason","Retry the connection once credentials/network are fixed"],"exampleFix":null,"handlingStrategy":"retry","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"}