{"record":{"id":"1e0f8ee633d1353d","repo":"karatelabs/karate","slug":"missing-array-argument-patterns","errorCode":null,"errorMessage":"missing array argument 'patterns': ","messagePattern":"missing array argument 'patterns': ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/Driver.java","lineNumber":387,"sourceCode":"            case DriverApi.CLEAR_COOKIES -> (JavaCallable) (ctx, args) -> {\n                clearCookies();\n                return null;\n            };\n            case DriverApi.DELETE_COOKIE -> (JavaCallable) (ctx, args) -> {\n                deleteCookie(String.valueOf(args[0]));\n                return null;\n            };\n\n            // Request interception\n            // V1 compat:  driver.intercept({ patterns: [...], mock: 'classpath:mock.feature' })\n            // V2 handler:  driver.intercept({ patterns: [...], handler: function(req){ return { status: 200, body: '...' } } })\n            case DriverApi.INTERCEPT -> (JavaCallable) (ctx, args) -> {\n                Object arg = args[0];\n                if (arg instanceof Map) {\n                    Map<String, Object> configMap = (Map<String, Object>) arg;\n                    List<Object> patterns = (List<Object>) configMap.get(\"patterns\");\n                    if (patterns == null) {\n                        throw new RuntimeException(\"missing array argument 'patterns': \" + configMap);\n                    }\n                    // Extract URL pattern strings from pattern maps or plain strings\n                    List<String> urlPatterns = new java.util.ArrayList<>();\n                    for (Object p : patterns) {\n                        if (p instanceof Map) {\n                            Object urlPattern = ((Map<String, Object>) p).get(\"urlPattern\");\n                            urlPatterns.add(urlPattern != null ? String.valueOf(urlPattern) : \"*\");\n                        } else {\n                            urlPatterns.add(String.valueOf(p));\n                        }\n                    }\n                    Object handlerObj = configMap.get(\"handler\");\n                    String mock = configMap.get(\"mock\") != null ? String.valueOf(configMap.get(\"mock\")) : null;\n                    if (handlerObj instanceof JavaCallable jsHandler) {\n                        // V2: inline JS handler\n                        intercept(urlPatterns, request -> {\n                            Object result = jsHandler.call(ctx, request);\n                            if (result instanceof InterceptResponse ir) {","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/Driver.java#L369-L405","documentation":"Driver.jsGet's INTERCEPT API callable validates the configuration map passed to driver.intercept(). When the map has no 'patterns' key (or it is null), it throws this RuntimeException including the offending config map. The patterns array is mandatory because it defines which URLs the intercept applies to.","triggerScenarios":"driver.intercept({ mock: ... }) without the required 'patterns' array; a config built programmatically where the patterns key was misspelled ('pattern', 'urlPatterns') or set to null.","commonSituations":"Copy-pasted intercept examples where the patterns entry was dropped; JS object built dynamically and the key name didn't match; mixing up intercept configuration shapes between Karate versions.","solutions":["Add the required patterns array: driver.intercept({ patterns: ['https://example.com/*'], mock: ... })","Check the key spelling — it must be exactly 'patterns'","Verify the value is a (JS) array of URL pattern strings or pattern objects, not a single string or null"],"exampleFix":"// before\ndriver.intercept({ mock: { status: 200, body: 'ok' } });\n// after\ndriver.intercept({ patterns: ['https://api.example.com/data'], mock: { status: 200, body: 'ok' } });","handlingStrategy":"validation","validationCode":"// in Karate JS, before calling:\n// if (!config.patterns) throw new Error('intercept config requires patterns array');","typeGuard":"// JS: if (Array.isArray(cfg.patterns) && cfg.patterns.length > 0) { ... }","tryCatchPattern":"try { driver.intercept(cfg); } catch (RuntimeException e) { if (e.getMessage().contains(\"missing array argument 'patterns'\")) { /* fix config */ } else throw e; }","preventionTips":["Always include patterns first when writing intercept configs","Copy config shapes from current Karate docs, not old examples","Keep key names in shared constants"],"tags":["ui","driver","intercept","network-mocking"],"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"}