{"record":{"id":"0cf1d393bf5492cd","repo":"karatelabs/karate","slug":"runtimeexception-result-message","errorCode":null,"errorMessage":"RuntimeException(result.message)","messagePattern":"RuntimeException\\(result\\.message\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/match/Match.java","lineNumber":63,"sourceCode":"        EACH_NOT_EQUALS,\n        EACH_CONTAINS,\n        EACH_NOT_CONTAINS,\n        EACH_CONTAINS_ONLY,\n        EACH_CONTAINS_ANY,\n        EACH_CONTAINS_DEEP,\n        WITHIN,\n        NOT_WITHIN\n\n    }\n\n    public static Value evaluate(Object actual, Context context, BiConsumer<Context, Result> onResult) {\n        return new Value(Value.parseIfJsonOrXmlString(actual), context, onResult);\n    }\n\n    public static Value that(Object actual) {\n        return new Value(Value.parseIfJsonOrXmlString(actual), null, (context, result) -> {\n            if (!result.pass) {\n                throw new RuntimeException(result.message);\n            }\n        });\n    }\n\n    public static Result execute(Engine engine, Type matchType, Object actual, Object expected) {\n        return execute(engine, matchType, actual, expected, false);\n    }\n\n    public static Result execute(Engine engine, Type matchType, Object actual, Object expected, boolean matchEachEmptyAllowed) {\n        try (Value actualValue = new Value(actual); Value expectedValue = new Value(expected)) {\n            Operation op = new Operation(engine, matchType, actualValue, expectedValue, matchEachEmptyAllowed);\n            op.execute();\n            return op.getResult();\n        }\n    }\n\n    public static Result execute(Engine engine, Type matchType, Object actual, Object expected, long memoryThreshold) {\n        try (Value actualValue = new Value(actual, null, null, true, memoryThreshold);","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/match/Match.java#L45-L81","documentation":"Match.that() runs a match expression against actual data and, instead of returning a Result, throws a plain RuntimeException carrying the match failure message when the match does not pass. It is the assertion-style entry point of the karate match API: the library throws whenever `result.pass` is false so the failure surfaces immediately with the detailed diff/message produced by the match engine.","triggerScenarios":"Calling Match.that(actual).isEqualTo(expected) (or any of contains/containsDeep/containsOnly/each*/within etc.) when the actual value does not satisfy the expected condition; the throw happens in the onResult callback registered by that().","commonSituations":"Test assertions where server responses or transformed payloads differ from expectations: extra/missing JSON keys, wrong types (string vs number), ordering assumptions with containsOnly, or XML/JSON strings passed that fail to parse into the expected shape.","solutions":["Print or log result.message from the equivalent Match.execute()/equals result to see the exact diff before fixing the expectation","Correct the expected value to match the actual payload (keys, types, ordering)","If actual data is legitimately variable, loosen the matcher (containsAny, containsOnly, schema-style partial match) instead of strict equality","Ensure the actual input is valid JSON/XML if it came in as a string; use Value.parseIfJsonOrXmlString semantics - plain strings are compared literally"],"exampleFix":"// before\nMatch.that(response.token).isEqualTo(\"abc123\"); // throws on mismatch\n// after\nMatch.that(response.token).isTypeOf(\"string\").isNotNull(); // assert type/presence, or\nif (!Match.execute(engine, Match.Type.EQUALS, actual, expected).pass) {\n    // handle mismatch programmatically instead of throwing\n}","handlingStrategy":"try-catch","validationCode":"if (actual == null) { throw new IllegalArgumentException(\"actual is null before match\"); }","typeGuard":"boolean isParsablePayload(Object o) { return o instanceof java.util.Map || o instanceof java.util.List || o instanceof String; }","tryCatchPattern":"try {\n    Match.that(actual).isEqualTo(expected);\n} catch (RuntimeException e) {\n    // e.getMessage() contains the match diff; log and continue or rethrow as assertion failure\n    log.warn(\"match failed: {}\", e.getMessage());\n}","preventionTips":["Use Match.execute(...) to get a Result instead of throwing when you need programmatic handling","Assert types with isTypeOf before strict equality matches","Print the actual payload next to the expected in failure reports"],"tags":["match","assertion","json","runtime"],"backgroundTag":"schema-validation-failed","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"}