Sending Groovy Exception Messages Back to Client over Gremlin Server (Titan 1.0.0)

93 views
Skip to first unread message

Vivek Krishnan

unread,
Sep 27, 2016, 5:18:56 AM9/27/16
to Gremlin-users
I am currently working on an application in which I use Titan DB as a backend and connect to it using Gremlin-Server.

My goal is to be able to throw exceptions in my Groovy scripts and have these exception messages passed back to the gremlin client so that my application can give a proper response to what when wrong during execution. Currently, I do not believe that this is supported in Gremlin Server.

I am currently using the HttpChannelizer defined at gremlin/server/handler/HttpGremlinEndpointHandler.java

Line 255:
evalFuture.exceptionally(t -> {
                    sendError
(ctx, INTERNAL_SERVER_ERROR,
                           
String.format("Error encountered evaluating script: %s", requestArguments.getValue0()), Optional.of(t));
                    promise
.setFailure(t);
                   
return null;
               
});


Line 447:
private static void sendError(final ChannelHandlerContext ctx, final HttpResponseStatus status,
                                  final String message, final Optional<Throwable> t) {
        if (t.isPresent())
            logger.warn(String.format("Invalid request - responding with %s and %s", status, message), t.get());
        else
            logger.warn(String.format("Invalid request - responding with %s and %s", status, message));

        errorMeter.mark();
        final ObjectNode node = mapper.createObjectNode();
        node.put("message", message);
        final FullHttpResponse response = new DefaultFullHttpResponse(
                HTTP_1_1, status, Unpooled.copiedBuffer(node.toString(), CharsetUtil.UTF_8));
        response.headers().set(CONTENT_TYPE, "application/json");

        // Close the connection as soon as the error message is sent.
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
    }

This is the part of the handler that deals with exceptions thrown during execution of the gremlin query. As you can see, the sendError is being called such that the HttpResponseStatus code is INTERNAL_SERVER_ERROR(500) and the error message is set to be "Error encountered evaluating script: <prog_name>"

Even though the exception t is passed into the sendError function, the error message is only logger server side and not included in the http response.



I could return error messages in the Http response data by catching exceptions in Groovy and returning strings with the error messages, but this seems gimmicky and prone to some bugs in the future. I want to know if it would be worthwhile to edit the HttpChannelizer to send the exception message to the client if the exception t is present.

What would be the best way to notify the client about specific errors?




Stephen Mallette

unread,
Sep 27, 2016, 6:30:39 AM9/27/16
to Gremlin-users
REST could use some nicer error handling (as could streaming protocol for that matter). There's a bunch of tickets related to that:


Those are mostly just ideas at this point. I'm not sure there's been any consensus on what should actually be implemented. Feel free to comment on those issues or start a mailing list thread on dev ( https://lists.apache.org/list.html?d...@tinkerpop.apache.org ) if you'd like to help drive some kind of change forward around this.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/67de4038-28ea-45f8-8df5-013ef97e7ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages