{"record":{"id":"29838a937347cdf0","repo":"karatelabs/karate","slug":"start-config-requires-mock-key-with-feature-path","errorCode":null,"errorMessage":"start() config requires 'mock' key with feature path","messagePattern":"start\\(\\) config requires 'mock' key with feature path","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":952,"sourceCode":"     */\n    @SuppressWarnings(\"unchecked\")\n    private JavaInvokable start() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"start() needs at least one argument: feature path or config map\");\n            }\n            Object arg = args[0];\n            MockServer.Builder builder;\n\n            if (arg instanceof String path) {\n                // Simple path: karate.start('api.feature')\n                builder = MockServer.feature(root.resolve(path));\n            } else if (arg instanceof Map) {\n                // Config map: karate.start({ mock: 'api.feature', port: 8080 })\n                Map<String, Object> config = (Map<String, Object>) arg;\n                String mockPath = (String) config.get(\"mock\");\n                if (mockPath == null) {\n                    throw new RuntimeException(\"start() config requires 'mock' key with feature path\");\n                }\n                builder = MockServer.feature(root.resolve(mockPath));\n\n                if (config.containsKey(\"port\")) {\n                    builder.port(((Number) config.get(\"port\")).intValue());\n                }\n                if (config.containsKey(\"ssl\")) {\n                    builder.ssl(Boolean.TRUE.equals(config.get(\"ssl\")));\n                }\n                if (config.containsKey(\"cert\")) {\n                    builder.certPath((String) config.get(\"cert\"));\n                }\n                if (config.containsKey(\"key\")) {\n                    builder.keyPath((String) config.get(\"key\"));\n                }\n                if (config.containsKey(\"arg\")) {\n                    builder.arg((Map<String, Object>) config.get(\"arg\"));\n                }","sourceCodeStart":934,"sourceCodeEnd":970,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L934-L970","documentation":"When `karate.start()` receives a Map, the library treats it as a mock-server config and requires a `mock` key holding the feature file path. A Map without `mock` gives the server nothing to mount, so it throws this error telling you exactly which key is required.","triggerScenarios":"karate.start({ port: 8080 }) or karate.start({ features: [...], ssl: true }) — any config Map whose `mock` key is absent or null (e.g. config.get(\"mock\") returns null because the key is misspelled as 'feature', 'mocks', or 'path').","commonSituations":"Misspelling the key ('mocks', 'feature', 'file'); copying a config from karate-config style objects where the feature key is named differently; building the config programmatically and forgetting to set mock; using a real HTTP mock config from a different tool with different key names.","solutions":["Add the required key: karate.start({ mock: 'api.feature' })","Fix key misspellings — the key must be exactly 'mock'","If you meant to start a real server rather than a mock, use karate.fork()/karate.exec() instead","Assert the config before calling: if (!config.mock) throw 'mock path missing'"],"exampleFix":"// before\nkarate.start({ feature: 'api.feature', port: 8080 }) // wrong key\n// after\nkarate.start({ mock: 'api.feature', port: 8080 })","handlingStrategy":"validation","validationCode":"// JS\nif (cfg && !cfg.mock) throw new Error('config map to karate.start() must include mock: <feature path>');\nkarate.start(cfg);","typeGuard":"function isStartConfig(cfg) { return cfg !== null && typeof cfg === 'object' && typeof cfg.mock === 'string' && cfg.mock.length > 0; }","tryCatchPattern":"try { var server = karate.start(cfg); } catch (e) { if (('' + e).indexOf(\"'mock' key\") !== -1) { karate.log('config missing mock key, keys=' + Object.keys(cfg)); } throw e; }","preventionTips":["Key must be exactly 'mock', not 'feature' or 'mocks'","Validate config maps before passing to start()","Add the mock key when building configs programmatically"],"tags":["javascript","mock-server","missing-config-key"],"backgroundTag":"missing-required-config-field","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"}