{"record":{"id":"34288f5110ed9322","repo":"karatelabs/karate","slug":"configure-logging-mask-expects-a-map-got-maskvalue-getclass","errorCode":null,"errorMessage":"configure 'logging.mask' expects a map, got: ${maskValue.getClass().getName()}","messagePattern":"configure 'logging\\.mask' expects a map, got: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateConfig.java","lineNumber":656,"sourceCode":"            boolean pretty = toBoolean(map.get(\"pretty\"));\n            this.logging.put(\"pretty\", pretty);\n            LogContext.get().setPretty(pretty);\n        }\n        if (map.containsKey(\"mask\")) {\n            Object maskValue = map.get(\"mask\");\n            if (maskValue == null) {\n                this.logging.remove(\"mask\");\n                this.compiledMask = null;\n                LogContext.get().setMask(null);\n            } else if (maskValue instanceof Map<?, ?> maskMap) {\n                @SuppressWarnings(\"unchecked\")\n                Map<String, Object> mm = (Map<String, Object>) maskMap;\n                LogMask compiled = LogMask.fromMap(mm);\n                this.logging.put(\"mask\", mm);\n                this.compiledMask = compiled;\n                LogContext.get().setMask(compiled);\n            } else {\n                throw new RuntimeException(\"configure 'logging.mask' expects a map, got: \" + maskValue.getClass().getName());\n            }\n        }\n    }\n\n    /**\n     * Push this config's logging settings into the given LogContext.\n     * Called by {@link ScenarioRuntime#call()} after it allocates a fresh thread-local\n     * LogContext, so any mask / pretty values set in karate-config.js (or a prior step)\n     * survive into the scenario's HTTP logging.\n     */\n    public void applyLoggingToContext(LogContext ctx) {\n        if (ctx == null) return;\n        ctx.setMask(compiledMask);\n        Object prettyVal = logging.get(\"pretty\");\n        ctx.setPretty(prettyVal == null ? true : toBoolean(prettyVal));\n    }\n\n    /**","sourceCodeStart":638,"sourceCodeEnd":674,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateConfig.java#L638-L674","documentation":"Within 'configure logging', the optional 'mask' key must itself be a Map matching LogMask.fromMap's expected shape ({ headers: [...], jsonPaths: [...], patterns: [...] }). If mask is present but not a Map, configureLogging throws with the value's class name.","triggerScenarios":"'configure logging = { mask: \"headers.json\" }' or mask set to a list/string/other non-map value; a JS variable holding the mask config that resolves to null or an unexpected type.","commonSituations":"Passing a file path string where an inline mask map is expected; building the mask object in JS and accidentally assigning the wrong variable; copy-pasting mask config in the wrong nesting level (mask directly under logging but as a scalar).","solutions":["Ensure mask is a map, e.g. 'configure logging = { mask: { headers: [\"Authorization\"], jsonPaths: [\"$.password\"], patterns: [] } }'","Alternatively use the declarative form 'configure logging = { mask: { headers: [...], jsonPaths: [...], patterns: [...] } }' as documented in the error text for configure mask","Print the value with karate.log before configuring to confirm its type"],"exampleFix":"// before\n* configure logging = { mask: 'mask-config.json' }\n// after\n* configure logging = { mask: { headers: ['Authorization'], jsonPaths: ['$.password'], patterns: [] } }","handlingStrategy":"type-guard","validationCode":"var isValidMask = function (m) { return m !== null && typeof m === 'object' && !(m instanceof Array); };","typeGuard":"function isMaskMap(logging) { return !logging.mask || (typeof logging.mask === 'object' && !Array.isArray(logging.mask)); }","tryCatchPattern":"try { karate.configure('logging', cfg); } catch (RuntimeException e) { if (e.getMessage().contains(\"logging.mask' expects a map\")) { log.error('mask must be { headers, jsonPaths, patterns } object'); } throw e; }","preventionTips":["Keep mask as an inline object literal, not a path string","Verify nested structure: logging.mask, not logging.mask.headers at top level","Unit-test karate-config.js config construction"],"tags":["configuration","logging","mask","type-mismatch"],"backgroundTag":"config-type-mismatch","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"}