{"record":{"id":"4867388f53e3221a","repo":"t8y2/dbx","slug":"not-connected-call-connect-first-486738","errorCode":null,"errorMessage":"Not connected. Call connect first.","messagePattern":"Not connected\\. Call connect first\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/main.go","lineNumber":426,"sourceCode":"\t\tamqpConfig.TLSClientConfig = &tls.Config{\n\t\t\tServerName:         endpoint.Host,\n\t\t\tInsecureSkipVerify: tlsSkipVerify(config),\n\t\t}\n\t}\n\treturn amqp.DialConfig(uri.String(), amqpConfig)\n}\n\nfunc (s *server) channelFor(params jsonObject) (*amqp.Channel, error) {\n\tdefaultVhost := \"/\"\n\tif s.cachedConnection != nil {\n\t\tdefaultVhost = stringOrDefault(s.cachedConnection, \"virtual_host\", \"/\")\n\t}\n\tvhost := effectiveVhost(params, s.cachedConnection)\n\tif vhost == defaultVhost {\n\t\treturn s.primaryChannel()\n\t}\n\tif s.cachedConnection == nil {\n\t\treturn nil, errors.New(\"Not connected. Call connect first.\")\n\t}\n\tif client := s.vhostClients[vhost]; client != nil && client.isOpen() {\n\t\treturn client.channel, nil\n\t} else if client != nil {\n\t\tclient.close()\n\t\tdelete(s.vhostClients, vhost)\n\t}\n\tconfig := deepCopyObject(s.cachedConnection)\n\tconfig[\"virtual_host\"] = vhost\n\tconnection, err := openConnection(config)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tchannel, err := connection.Channel()\n\tif err != nil {\n\t\tcloseConnection(connection)\n\t\treturn nil, err\n\t}","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/main.go#L408-L444","documentation":"channelFor first tries the primary/default-vhost channel; for a non-default vhost it needs a cached connection established by connect(). If no cached connection exists it cannot open a vhost client and throws this error telling you to connect first.","triggerScenarios":"Calling createTopic/deleteTopic/getTopicStats/getTopicConfig/purgeQueue/applyBinding with a virtual_host other than the default before mq_connect was ever called (or after its cached connection was cleared).","commonSituations":"Using an agent instance fresh from construction for vhost-scoped ops; a previous connect failed silently and was ignored; long-lived process where cached state was reset but ops continue.","solutions":["Call mq_connect before performing vhost-scoped operations","Check/propagate the error from connect instead of ignoring it","Or pass the default vhost (omit virtual_host) so primaryChannel is used"],"exampleFix":"// before\nagent.Call(\"mq_purge_queue\", map[string]any{\"topic\": \"q\", \"virtual_host\": \"staging\"})\n// after\nagent.Call(\"mq_connect\", map[string]any{\"addresses\": \"rabbit:5672\"})\nagent.Call(\"mq_purge_queue\", map[string]any{\"topic\": \"q\", \"virtual_host\": \"staging\"})","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"_, err := agent.Call(\"mq_purge_queue\", params)\nif err != nil && strings.Contains(err.Error(), \"Not connected\") {\n\tif _, cerr := agent.Call(\"mq_connect\", connectCfg); cerr != nil { return cerr }\n\t_, err = agent.Call(\"mq_purge_queue\", params) // retry once after connect\n}","preventionTips":["Always call mq_connect before queue operations, including vhost-scoped ones","Handle connect errors instead of ignoring them","Wrap operations with an ensureConnected helper"],"tags":["rabbitmq","connection","lifecycle"],"backgroundTag":"not-connected","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}