Truncate error message for "method code too large" exceptions CTR
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b3e301e6 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b3e301e6 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b3e301e6 Branch: refs/heads/TINKERPOP-1784 Commit: b3e301e66ae7410aac6e7c35186ab8d909166ca0 Parents: 9f501cd Author: Stephen Mallette <[email protected]> Authored: Wed Oct 4 08:27:31 2017 -0400 Committer: Stephen Mallette <[email protected]> Committed: Wed Oct 4 08:27:31 2017 -0400 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../gremlin/server/op/AbstractEvalOpProcessor.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 9f98c08..5ea3034 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima [[release-3-2-7]] === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET) +* Truncate the script in error logs and error return messages for "Method code too large" errors in Gremlin Server. * `ReferenceVertex` was missing its `label()` string. `ReferenceElement` now supports all label handling. * Fixed a bug where bytecode containing lambdas would randomly select a traversal source from bindings. * Deprecated `GremlinScriptEngine.eval()` methods and replaced them with new overloads that include the specific `TraversalSource` to bind to. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b3e301e6/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java index 46b3c8d..5c43b4d 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java @@ -312,7 +312,7 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { // up being favorable for this problem if (t instanceof MultipleCompilationErrorsException && t.getMessage().contains("Method code too large!") && ((MultipleCompilationErrorsException) t).getErrorCollector().getErrorCount() == 1) { - final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", msg); + final String errorMessage = String.format("The Gremlin statement that was submitted exceed the maximum compilation size allowed by the JVM, please split it into multiple smaller statements - %s", trimMessage(msg)); logger.warn(errorMessage); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_SCRIPT_EVALUATION) .statusMessage(errorMessage) @@ -330,6 +330,18 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { }); } + /** + * Used to decrease the size of a Gremlin script that triggered a "method code too large" exception so that it + * doesn't log a massive text string nor return a large error message. + */ + private RequestMessage trimMessage(final RequestMessage msg) { + final RequestMessage trimmedMsg = RequestMessage.from(msg).create(); + if (trimmedMsg.getArgs().containsKey(Tokens.ARGS_GREMLIN)) + trimmedMsg.getArgs().put(Tokens.ARGS_GREMLIN, trimmedMsg.getArgs().get(Tokens.ARGS_GREMLIN).toString().substring(0, 1021) + "..."); + + return trimmedMsg; + } + @FunctionalInterface public interface BindingSupplier { public Bindings get() throws OpProcessorException;
