PendingJavaScriptInvocation implements PendingJavaScriptResult { public void completeExceptionally(JsonValue value) { assert isSubscribed(); String message = value.asString(); if (errorHandler != null) { errorHandler.accept(message); } else { getLogger().debug("Ignored error from JavaScript: {}", message); } } PendingJavaScriptInvocation(StateNode owner,
            JavaScriptInvocation invocation); StateNode getOwner(); boolean isSubscribed(); void complete(JsonValue value); void completeExceptionally(JsonValue value); @Override boolean cancelExecution(); @Override boolean isSentToBrowser(); @Override void then(SerializableConsumer<JsonValue> successHandler,
            SerializableConsumer<String> errorHandler); boolean isCanceled(); JavaScriptInvocation getInvocation();  }
@Test public void untypedFuture_fail() { invocation.toCompletableFuture().whenComplete(jsonFutureHandler); invocation.completeExceptionally(fooJsonString); assertFail(); }
@Test public void typedFuture_fail() { invocation.toCompletableFuture(String.class) .whenComplete(stringFutureHandler); invocation.completeExceptionally(fooJsonString); assertFail(); }
@Test public void blockFromSessionThreadAfterFailing_doesNotThrow() throws Exception { MockVaadinSession session = new MockVaadinSession(); session.runWithLock(() -> { CompletableFuture<JsonValue> completableFuture = invocation .toCompletableFuture(); String errorMessage = "error message"; invocation.completeExceptionally(Json.create(errorMessage)); for (Callable<JsonValue> action : createBlockingActions( completableFuture)) { try { action.call(); Assert.fail("Execution should have failed"); } catch (ExecutionException | CompletionException e) { JavaScriptException cause = (JavaScriptException) e .getCause(); Assert.assertEquals(errorMessage, cause.getMessage()); } } return null; }); }