Kinotic-Foundation / continuum-framework

Iot and Microservices framework
https://kinotic-foundation.github.io/continuum-framework/
Apache License 2.0
4 stars 0 forks source link

Determine if it is possible for Service Invoker to catch unhandled errors that handle inside a Async method. #32

Open NavidMitchell opened 4 months ago

NavidMitchell commented 4 months ago

The service invoker does not return the error if a method that returns a CompletableFuture encounters an unhandled exception and never completes the future.

I saw this when the code below tried to deserialize the json and failed.

org.kinotic.structures.internal.api.services.sql.DefaultElasticVertxClient Line: 61


public CompletableFuture<TranslateResponse> translateSql(String statement,
                                                             List<?> params){
        VertxCompletableFuture<TranslateResponse> responseFuture = new VertxCompletableFuture<>(vertx);
        JsonObject json = new JsonObject().put("query", statement);
        if(params != null) {
            JsonArray paramsJson = new JsonArray();
            for(Object param : params){
                paramsJson.add(param);
            }
            json.put("params", paramsJson);
        }
        sqlTranslateRequest.sendJsonObject(json, ar -> {
            if(ar.succeeded()){
                TranslateResponse translateResponse = TranslateResponse.of(builder -> {
                    builder.withJson(new ByteArrayInputStream(ar.result()
                                                                .body()
                                                                .getBytes()));
                    return builder;
                });
                responseFuture.complete(translateResponse);
            }else{
                responseFuture.completeExceptionally(ar.cause());
            }
        });
        return responseFuture;
    }
NavidMitchell commented 4 months ago

This appears to be happening since the TranslateResponse.of code is running on a different thread than the service invocation.