{"record":{"id":"a83d98322fa49b1a","repo":"karatelabs/karate","slug":"unhandled-promise-rejection-name-jsmessage","errorCode":null,"errorMessage":"unhandled promise rejection: <name>: <jsMessage>","messagePattern":"unhandled promise rejection: <name>: <jsMessage>","errorType":"exception","errorClass":"EngineException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/AsyncSupport.java","lineNumber":870,"sourceCode":"            if (!promise.isRejectionHandled() && promise.claimRejectionReport()) {\n                terminal.add(promise);\n            }\n        }\n        if (terminal.isEmpty()) {\n            return;\n        }\n        for (int i = 1; i < terminal.size(); i++) {\n            warn(engine, \"unhandled promise rejection: \" + describe(terminal.get(i).settledValue()));\n        }\n        reportFailure(engine, \"unhandled promise rejection\", terminal.get(0).settledValue());\n    }\n\n    private static void reportFailure(Engine engine, String prefix, Object reason) {\n        if (engine.asyncRejectionWarnOnly()) {\n            warn(engine, prefix + \": \" + describe(reason));\n            return;\n        }\n        throw asEngineException(prefix, reason);\n    }\n\n    private static void warn(Engine engine, String message) {\n        logger.warn(message);\n        java.util.function.Consumer<String> consumer = engine.root().onConsoleLog;\n        if (consumer != null) {\n            consumer.accept(message);\n        }\n    }\n\n    static EngineException asEngineException(String prefix, Object reason) {\n        String name = null;\n        String jsMessage = null;\n        if (reason instanceof ObjectLike obj) {\n            if (obj.getMember(\"name\") instanceof String s && !s.isEmpty()) {\n                name = s;\n            }\n            if (obj.getMember(\"message\") instanceof String s) {","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/AsyncSupport.java#L852-L888","documentation":"An asynchronous JS operation (a rejected promise) failed with no handler attached. Depending on `asyncRejectionWarnOnly`, AsyncSupport either logs a warning via `onConsoleLog`/logger or throws an engine exception with message \"unhandled promise rejection: <name>: <jsMessage>\". This mirrors the browser/Node unhandledrejection behavior inside Karaté's JS engine.","triggerScenarios":"A promise created in JS (e.g. via async helpers or karate's async APIs) rejects and no `.catch()`/try-await handles it before the microtask queue drains; reportFailure is invoked with the rejection reason.","commonSituations":"Forgetting await on an async call whose promise rejects; fire-and-forget promises without catch; network or assertion failures inside async background tasks during scenario execution.","solutions":["Attach `.catch(handler)` or `try { await ... } catch` to every promise that can reject.","Inspect the `<jsMessage>` portion of the message to find the underlying rejection cause.","If warnings are acceptable, configure the engine's asyncRejectionWarnOnly(true) so rejections log instead of aborting."],"exampleFix":"// before\nasyncWork(); // rejects unhandled\n\n// after\nasyncWork().catch(e => console.log('handled: ' + e));\n// or\ntry { await asyncWork(); } catch (e) { console.log('handled: ' + e); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// JS: never leave promises unhandled\nasyncWork()\n  .then(handle)\n  .catch(function (e) { console.log('rejection handled: ' + e); });\n// or: try { var r = await asyncWork(); } catch (e) { console.log(e); }","preventionTips":["Attach .catch to every promise, including fire-and-forget calls.","Prefer async/await with try/catch so rejections cannot be dropped.","Review async helpers used in scenarios for missing error handlers."],"tags":["javascript","async","promise","unhandled-rejection"],"backgroundTag":"unhandled-promise-rejection","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"}