{"record":{"id":"5daa29b626533f31","repo":"karatelabs/karate","slug":"configure-logging-mask-patterns-missing-regex-skipped","errorCode":null,"errorMessage":"configure logging.mask.patterns[{}] missing 'regex' — skipped","messagePattern":"configure logging\\.mask\\.patterns\\[(.+?)\\] missing 'regex' — skipped","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/output/LogMask.java","lineNumber":114,"sourceCode":"                }\n            }\n        }\n        List<String> jsonPaths = new ArrayList<>();\n        if (map.get(\"jsonPaths\") instanceof List<?> list) {\n            for (Object item : list) {\n                if (item != null) {\n                    jsonPaths.add(item.toString());\n                }\n            }\n        }\n        List<PatternRule> patternRules = new ArrayList<>();\n        if (map.get(\"patterns\") instanceof List<?> list) {\n            int idx = 0;\n            for (Object item : list) {\n                if (item instanceof Map<?, ?> pm) {\n                    Object regex = pm.get(\"regex\");\n                    if (regex == null) {\n                        logger.warn(\"configure logging.mask.patterns[{}] missing 'regex' — skipped\", idx);\n                        idx++;\n                        continue;\n                    }\n                    Object rep = pm.get(\"replacement\");\n                    String repStr = rep == null ? replacement : rep.toString();\n                    try {\n                        patternRules.add(new PatternRule(Pattern.compile(regex.toString()), repStr));\n                    } catch (PatternSyntaxException e) {\n                        // Skip rather than fail-fast — a typo in one rule shouldn't blow up\n                        // the whole config-js eval. The warn names the entry so the user\n                        // can find it. Other rules in the same mask still apply.\n                        logger.warn(\"configure logging.mask.patterns[{}] invalid regex '{}': {} — skipped\",\n                                idx, regex, e.getDescription());\n                    }\n                }\n                idx++;\n            }\n        }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/output/LogMask.java#L96-L132","documentation":"When parsing a `configure logging.mask` map, each entry in the `patterns` list must contain a `regex` key. If it is missing, LogMask skips that entry and logs this warning instead of failing the whole config eval, so the remaining mask rules still apply.","triggerScenarios":"Calling `karate.configure('logging.mask', { patterns: [{ replacement: '***' }] })` — a pattern entry without a `regex` key; also when regex is present but null (e.g. built dynamically from a variable that is null).","commonSituations":"Typo'd key name (`pattern`, `regEx`, `expression`) instead of `regex`; dynamically assembled mask config where a value failed to load; copy-paste of a headers/jsonPaths-style entry into the patterns list.","solutions":["Add the required `regex` key to every entry in the patterns list","Check for key-name typos: the key must be exactly `regex`","If building the config dynamically, filter out entries without a regex before configuring","Check the warned index in the message to locate the offending entry in the list"],"exampleFix":"// before\nkarate.configure('logging.mask', { patterns: [{ replacement: '***' }] })\n// after\nkarate.configure('logging.mask', { patterns: [{ regex: '[0-9]{16}', replacement: '***' }] })","handlingStrategy":"validation","validationCode":"var patterns = List.of(Map.of(\"regex\", \"[0-9]{16}\", \"replacement\", \"***\"));\nfor (var p : patterns) {\n    if (!p.containsKey(\"regex\") || p.get(\"regex\") == null)\n        throw new IllegalArgumentException(\"mask pattern entry missing 'regex'\");\n}","typeGuard":"boolean hasRegex(Map<?,?> pm) { return pm.get(\"regex\") instanceof String s && !s.isBlank(); }","tryCatchPattern":null,"preventionTips":["Always include a `regex` key in every patterns entry","Validate mask config keys before calling configure","Build patterns from a shared constant/helper to avoid key typos"],"tags":["logging","configuration","regex","masking"],"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-19T12:17:13.211Z"}