Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: Wrap groovy script exceptions in a serializable Exception object #6628

Merged

Conversation

dakrone
Copy link
Member

@dakrone dakrone commented Jun 26, 2014

Fixes #6598

It prevents ES from trying to serialize the default Groovy exceptions, which want to carry over a lot of state that doesn't serialize properly.

fail("should have thrown an exception");
} catch (SearchPhaseExecutionException e) {
assertThat(ExceptionsHelper.detailedMessage(e) + "should have contained GroovyScriptExecutionException",
ExceptionsHelper.detailedMessage(e).contains("GroovyScriptExecutionException"), equalTo(true));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to be sure it contained that not_found wasn't found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I've added this.

@areek areek assigned rjernst and unassigned rjernst Jun 29, 2014
@dakrone
Copy link
Member Author

dakrone commented Jun 30, 2014

@kimchy I've added logging and catching a more generic exception to this PR.

I also discovered that compilation exceptions don't serialize properly either, so I've done the same thing if an exception occurs during compilation.

return loader.parseClass(script, generateScriptName());
} catch (Exception e) {
if (logger.isTraceEnabled()) {
logger.trace("Exception compiling Groovy script:", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we log the groovy script name here? and start with lower case e :) . Also, catch Throwable in case of assertions enabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the script name is going to be "Script1.groovy", "Script2.groovy", "Script3.groovy", is that actually helpful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about catching AssertionError directly? I am worried that catching Throwable means catching OutOfMemoryError and swallowing the exception (which we have to do for the groovy exceptions).

@kimchy
Copy link
Member

kimchy commented Jun 30, 2014

@dakrone added a few more comments

@dakrone
Copy link
Member Author

dakrone commented Jun 30, 2014

@kimchy thanks! I've addressed all of the feedback except for catching Throwable, instead I used catch (Exception|AssertionError e) { ... (and added a test for it) so it doesn't swallow an OutOfMemoryError. But I'm happy to change it if you think it would be better to catch that also.

return loader.parseClass(script, generateScriptName());
} catch (Exception|AssertionError e) {
if (logger.isTraceEnabled()) {
logger.trace("exception compiling Groovy script:", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to add the name of the script here to the failure log

@kimchy
Copy link
Member

kimchy commented Jun 30, 2014

LGTM, lets do the script name (since its tricky) in another change ++

@dakrone
Copy link
Member Author

dakrone commented Jun 30, 2014

Opened #6653 for this.

@dakrone dakrone merged commit 761ef5d into elastic:master Jun 30, 2014
@jpountz jpountz removed the review label Jul 16, 2014
@clintongormley clintongormley changed the title Wrap groovy script exceptions in a serializable Exception object Scripting: Wrap groovy script exceptions in a serializable Exception object Jul 16, 2014
@dakrone dakrone deleted the feature/groovy/exception-serialization branch September 9, 2014 13:47
@clintongormley clintongormley added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v1.3.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scripting: Wrap groovy script exceptions in a serializable Exception object
6 participants