{"record":{"id":"7914bfad1495ac2e","repo":"karatelabs/karate","slug":"channel-needs-a-type-argument-e-g-karate-channel-kafka","errorCode":null,"errorMessage":"channel() needs a type argument, e.g. karate.channel('kafka')","messagePattern":"channel\\(\\) needs a type argument, e\\.g\\. karate\\.channel\\('kafka'\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":1198,"sourceCode":"     * a JS function (e.g. iterating over a list of browser configs in a grid run),\n     * where Gherkin steps aren't reachable per iteration. Returns the same instance\n     * exposed via the {@code driver} root binding; after {@code driver.quit()} a\n     * subsequent read re-inits cleanly via {@link ScenarioRuntime#getDriver()}.\n     */\n    private io.karatelabs.driver.Driver getDriverLazy() {\n        ScenarioRuntime rt = getRuntime();\n        if (rt == null) {\n            throw new RuntimeException(\"karate.driver can only be read within a scenario\");\n        }\n        return rt.getDriver();\n    }\n\n    // ========== Channel Support ==========\n\n    private JavaInvokable channel() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"channel() needs a type argument, e.g. karate.channel('kafka')\");\n            }\n            String type = args[0].toString();\n            ScenarioRuntime rt = getRuntime();\n            if (rt == null) {\n                throw new RuntimeException(\"channel() can only be called within a scenario\");\n            }\n            // An ext (e.g. boot.ext('grpc')) may have registered a factory on the Suite at boot;\n            // it wins over the name-convention fallback. See Suite#registerChannelFactory.\n            FeatureRuntime fr = rt.getFeatureRuntime();\n            Suite suite = fr != null ? fr.getSuite() : null;\n            ChannelFactory factory = suite != null ? suite.getChannelFactory(type) : null;\n            try {\n                if (factory == null) {\n                    // No ext registered a factory for this type — resolve by name convention,\n                    // mirroring boot.ext: channel('grpc') -> io.karatelabs.ext.grpc.GrpcChannelFactory.\n                    String cap = Character.toUpperCase(type.charAt(0)) + type.substring(1);\n                    String factoryClass = \"io.karatelabs.ext.\" + type + \".\" + cap + \"ChannelFactory\";\n                    Class<?> clazz = Class.forName(factoryClass);","sourceCodeStart":1180,"sourceCodeEnd":1216,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L1180-L1216","documentation":"Argument guard in the karate.channel() JS binding: the channel type (e.g. 'kafka') identifies which messaging/connector implementation to instantiate, and without it no channel can be created. Fires when karate.channel() is invoked with no arguments; pass a channel-type string.","triggerScenarios":"`karate.channel()` with zero arguments; a dynamic type variable that is undefined causing an empty invocation.","commonSituations":"Configuring the channel type via a config value that was never set; writing generic helper JS that forgets the type parameter; typos dropped the argument during refactoring.","solutions":["Pass the channel type: karate.channel('kafka')","Ensure the type variable is defined before the call","Check available channel types (any registered factory, e.g. via a karate-<type> extension)."],"exampleFix":"// before\nvar ch = karate.channel();\n// after\nvar ch = karate.channel('kafka');","handlingStrategy":"validation","validationCode":"// JS\nif (type == null) karate.fail('karate.channel requires a type');\nvar ch = karate.channel(type);","typeGuard":"function isChannelType(s) { return typeof s === 'string' && s.length > 0; }","tryCatchPattern":"try { var ch = karate.channel(type); } catch (e) { karate.warn('channel failed: ' + e); }","preventionTips":["Always pass an explicit type string like 'kafka'","Default config-driven type values: type = type || 'kafka'","Keep channel type constants in one place"],"tags":["javascript","argument-validation","channels"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}