{"record":{"id":"6f1878c10cdcda6d","repo":"karatelabs/karate","slug":"dialog-dismiss-failed-error","errorCode":null,"errorMessage":"dialog dismiss failed: {error}","messagePattern":"dialog dismiss failed: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDialog.java","lineNumber":109,"sourceCode":"        // to prevent retry attempts that will also fail\n        if (response.isError()) {\n            // Log but don't throw - the dialog is effectively handled (gone)\n            throw new DriverException(\"dialog accept failed: \" + response.getError());\n        }\n    }\n\n    @Override\n    public void dismiss() {\n        if (handled) {\n            // Already handled - silently return to avoid race condition errors\n            return;\n        }\n        handled = true;\n        CdpResponse response = cdp.method(\"Page.handleJavaScriptDialog\")\n                .param(\"accept\", false)\n                .send();\n        if (response.isError()) {\n            throw new DriverException(\"dialog dismiss failed: \" + response.getError());\n        }\n    }\n\n    @Override\n    public boolean isHandled() {\n        return handled;\n    }\n\n    @Override\n    public String toString() {\n        return \"Dialog{type='\" + type + \"', message='\" + message + \"'}\";\n    }\n\n}\n","sourceCodeStart":91,"sourceCodeEnd":124,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDialog.java#L91-L124","documentation":"CdpDialog.dismiss() sends Page.handleJavaScriptDialog with accept=false and throws DriverException 'dialog dismiss failed: <error>' if CDP returns an error. As with accept, the usual cause is the dialog no longer existing when the command arrives.","triggerScenarios":"Calling dismiss() after the dialog was already handled or auto-closed; page navigated away, destroying the dialog; a prior accept()/dismiss() on the same dialog object.","commonSituations":"Event handler (setupEventHandlers) dismissing a dialog the test already handled; double dismissal in chained scenario steps; timing races in CI where the browser closed the dialog first.","solutions":["Check isHandled() before dismissing to avoid double-handling","Catch DriverException and treat it as success when the dialog already disappeared","Ensure only one code path (event handler or test step) manages the dialog","Add a small synchronization so handlers don't race the test's explicit dismiss"],"exampleFix":"// before\ndialog.dismiss(); // may fail if already handled by event handler\n// after\nif (!dialog.isHandled()) {\n    dialog.dismiss();\n}","handlingStrategy":"validation","validationCode":"if (dialog == null || dialog.isHandled()) {\n    return; // already dismissed or gone\n}","typeGuard":"boolean canDismiss(CdpDialog d) { return d != null && !d.isHandled(); }","tryCatchPattern":"try { dialog.dismiss(); }\ncatch (DriverException e) {\n    if (e.getMessage().startsWith(\"dialog dismiss failed\")) {\n        logger.info(\"dialog already handled elsewhere\");\n    } else throw e;\n}","preventionTips":["Single code path owns dialog dismissal (handler OR test, not both)","Check isHandled() before dismissing","Synchronize event handlers and explicit dismiss calls","Accept disappearance races as benign in CI"],"tags":["cdp","dialog","race-condition"],"backgroundTag":"invalid-state-transition","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"}