{"record":{"id":"b2a5cf385ceb796d","repo":"karatelabs/karate","slug":"prettyxml-needs-one-argument","errorCode":null,"errorMessage":"prettyXml() needs one argument","messagePattern":"prettyXml\\(\\) needs one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":436,"sourceCode":"            int step = args.length > 2 ? ((Number) args[2]).intValue() : 1;\n            List<Integer> result = new ArrayList<>();\n            if (step > 0) {\n                for (int i = start; i < end; i += step) {\n                    result.add(i);\n                }\n            } else if (step < 0) {\n                for (int i = start; i > end; i += step) {\n                    result.add(i);\n                }\n            }\n            return result;\n        };\n    }\n\n    static JavaInvokable prettyXml() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"prettyXml() needs one argument\");\n            }\n            Object obj = args[0];\n            if (obj instanceof Node) {\n                return Xml.toString((Node) obj, true);\n            } else if (obj instanceof String) {\n                return Xml.toString(Xml.toXmlDoc((String) obj), true);\n            } else {\n                throw new RuntimeException(\"prettyXml() argument must be XML node or string\");\n            }\n        };\n    }\n\n    static JavaInvokable repeat() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"repeat() needs two arguments: count and function\");\n            }\n            int count = ((Number) args[0]).intValue();","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L418-L454","documentation":"prettyXml() is a Karate JS utility that pretty-prints XML, accepting either an XML Node or an XML string (parsed via Xml.toXmlDoc). It throws this error when called with zero arguments, since there is no XML to format.","triggerScenarios":"karate.prettyXml() with no arguments, e.g. prettyXml() instead of prettyXml(responseXml).","commonSituations":"Logging an XML response in a Scenario without passing it; the variable was renamed or removed; copying a debug snippet with a placeholder argument.","solutions":["Pass the XML value: prettyXml(xmlNode) or prettyXml(xmlString).","Confirm the response variable actually holds the XML (e.g. response when the API returns XML, not a JSON-shaped field).","If the value might be absent, print a fallback: prettyXml(xml || '<empty/>')."],"exampleFix":"// before\nprint prettyXml()\n// after\nprint prettyXml(response)","handlingStrategy":"type-guard","validationCode":"if (responseXml) { print prettyXml(responseXml) } else { print '(no xml)' }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["prettyXml() takes one argument: an XML Node or XML string.","Verify the response actually is XML (check Content-Type) before calling prettyXml().","Assign the response to a variable, then print prettyXml(variable)."],"tags":["karate","javascript","argument-count","xml"],"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"}