{"record":{"id":"65bad6a1c7326e4d","repo":"t8y2/dbx","slug":"not-connected-call-connect-first","errorCode":null,"errorMessage":"Not connected. Call connect first.","messagePattern":"Not connected\\. Call connect first\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java","lineNumber":2635,"sourceCode":"\n    private static List<Throwable> causeChain(Throwable error) {\n        List<Throwable> chain = new ArrayList<>();\n        Set<Throwable> seen = Collections.newSetFromMap(new IdentityHashMap<>());\n        Throwable current = error;\n        for (int depth = 0; current != null && depth < 32 && seen.add(current); depth++) {\n            chain.add(current);\n            Throwable next = current.getCause();\n            if (next == current) {\n                break;\n            }\n            current = next;\n        }\n        return chain;\n    }\n\n    private static AdminClient requireAdmin() {\n        if (adminClient == null) {\n            throw new IllegalStateException(\"Not connected. Call connect first.\");\n        }\n        return adminClient;\n    }\n\n    private static JsonObject connectionObject(JsonObject params) {\n        JsonElement connection = params.get(\"connection\");\n        return connection != null && connection.isJsonObject()\n            ? connection.getAsJsonObject() : params;\n    }\n\n    private static int requestTimeout(JsonObject params) {\n        return intOrDefault(params, \"timeout_ms\", DEFAULT_REQUEST_TIMEOUT_MS);\n    }\n\n    private static Map<String, Object> nodeToMap(Node node) {\n        Map<String, Object> m = new LinkedHashMap<>();\n        m.put(\"id\", node.id());\n        m.put(\"host\", node.host());","sourceCodeStart":2617,"sourceCodeEnd":2653,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java#L2617-L2653","documentation":"requireAdmin() is the gate for every Kafka admin operation (topic metadata, configs, consumer groups, etc.). It throws IllegalStateException when adminClient is null, i.e. the agent has not established a connection via connect(), which is the only place AdminClient is created.","triggerScenarios":"Any admin tool call (list topics, describe cluster, consumer group ops) before connect() completes or after disconnect() nulls adminClient.","commonSituations":"Running an admin query at agent startup before connect finished; connect failed due to unreachable brokers/auth so adminClient was never set; the connection was closed between operations.","solutions":["Call the kafka connect tool first and verify it succeeded.","Fix connect failures (bootstrap servers, security protocol, SASL/TLS credentials) so adminClient gets initialized.","Reconnect after any disconnect/close before issuing admin calls.","Sequence your calls: connect -> admin operations -> disconnect."],"exampleFix":"// before\nagent.call(\"kafka.list_topics\", {})\n// after\nagent.call(\"kafka.connect\", {\"bootstrap_servers\": \"broker:9092\"})\nagent.call(\"kafka.list_topics\", {})","handlingStrategy":"try-catch","validationCode":"// call connect and confirm success before admin calls\nagent.call(\"kafka.connect\", cfg);\n// only then\nagent.call(\"kafka.list_topics\", {});","typeGuard":null,"tryCatchPattern":"try {\n    agent.adminOperation(params);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Not connected\")) {\n        agent.connect(cfg);\n        agent.adminOperation(params); // retry once after connect\n    } else { throw e; }\n}","preventionTips":["Initialize the connection as the first step of every session.","Investigate connect failures rather than proceeding with subsequent calls.","Re-issue connect after any disconnect/close event.","Serialize admin calls after connect completes; avoid concurrent disconnect/send races."],"tags":["kafka","lifecycle","not-connected","admin-client"],"backgroundTag":"not-connected-client","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"}